Skip to content

Instantly share code, notes, and snippets.

@pyghassen
Created September 19, 2014 10:50
Show Gist options
  • Save pyghassen/c3512ec50db355b43116 to your computer and use it in GitHub Desktop.
Save pyghassen/c3512ec50db355b43116 to your computer and use it in GitHub Desktop.
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