Created
September 19, 2014 10:50
-
-
Save pyghassen/c3512ec50db355b43116 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from uuid import uuid1 | |
from mongoengine import connect, Document | |
from mongoengine.fields import ( | |
StringField, IntField, DateTimeField, UUIDField, BooleanField, FloatField, | |
DictField | |
) | |
from .settings import MONGO_DBNAME | |
connect(MONGO_DBNAME) | |
class MyModel(Document): | |
""" | |
""" | |
uuid = UUIDField(default=uuid1) | |
name = StringField(required=True) | |
created_on = DateTimeField(default=datetime.datetime.now) | |
modified_on = DateTimeField() | |
delete_on = DateTimeField() | |
def to_dict(self): | |
""" | |
Converts a document to Dictionary. | |
""" | |
return { | |
"uuid": str(self.uuid), | |
"name": self.name, | |
"created_on": str(self.created_on), | |
"modified_on": str(self.modified_on), | |
"delete_on": str(self.delete_on), | |
} | |
def render_to_response(self): | |
""" | |
Converts a Dictionary to json. | |
""" | |
return { | |
str(self.uuid): self.to_dict() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment