Added basic querying - find and find_one

This commit is contained in:
Harry Marr 2009-11-19 01:09:58 +00:00
commit 8ec6fecd23
7 changed files with 141 additions and 12 deletions

View file

@ -59,6 +59,8 @@ class EmbeddedDocumentField(BaseField):
super(EmbeddedDocumentField, self).__init__(**kwargs)
def _to_python(self, value):
if not isinstance(value, self.document):
return self.document._from_son(value)
return value
def _to_mongo(self, value):
@ -68,6 +70,7 @@ class EmbeddedDocumentField(BaseField):
"""Make sure that the document instance is an instance of the
EmbeddedDocument subclass provided when the document was defined.
"""
# Using isinstance also works for subclasses of self.document
if not isinstance(value, self.document):
raise ValidationError('Invalid embedded document instance '
'provided to an EmbeddedDocumentField')