Skip to content

Instantly share code, notes, and snippets.

@anemitz
Created August 24, 2012 08:31
Show Gist options
  • Save anemitz/3447499 to your computer and use it in GitHub Desktop.
Save anemitz/3447499 to your computer and use it in GitHub Desktop.
MongoEngine DocumentBase
import datetime
from mongoengine import *
class DocumentBase(Document):
date_created = DateTimeField()
date_updated = DateTimeField()
def _type(self):
return unicode(self.__class__.__name__)
def save(self, *args, **kwargs):
kwargs['cascade'] = kwargs.get('cascade', False)
now = datetime.datetime.utcnow()
if not self.date_created:
self.date_created = now
self.date_updated = now
return super(DocumentBase, self).save(*args, **kwargs)
meta = {
'allow_inheritance': True,
'abstract': True,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment