Skip to content

Instantly share code, notes, and snippets.

@rozza
Created August 16, 2011 14:05
Show Gist options
  • Save rozza/1149167 to your computer and use it in GitHub Desktop.
Save rozza/1149167 to your computer and use it in GitHub Desktop.
Extended EmbeddedDocumentField for MongoEngine
class ExtendedEmbeddedDocumentField(BaseField):
"""An embedded document field attaches the owner_document to field,
when pulled from the database.
"""
def to_python(self, value):
if not isinstance(value, self.document_type):
embedded = self.document_type._from_son(value)
embedded._owner_document = self.owner_document
return embedded
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment