fixes for #325 issue

This commit is contained in:
Wilson Júnior 2011-10-19 06:30:41 -02:00
parent 76d771d20f
commit b09c52fc7e
3 changed files with 13 additions and 1 deletions

View File

@ -666,6 +666,9 @@ class ReferenceField(BaseField):
return pymongo.dbref.DBRef(collection, id_)
def prepare_query_value(self, op, value):
if value is None:
return None
return self.to_mongo(value)
def validate(self, value):
@ -743,6 +746,9 @@ class GenericReferenceField(BaseField):
return {'_cls': document._class_name, '_ref': ref}
def prepare_query_value(self, op, value):
if value is None:
return None
return self.to_mongo(value)

View File

@ -47,5 +47,5 @@ setup(name='mongoengine',
classifiers=CLASSIFIERS,
install_requires=['pymongo'],
test_suite='tests',
tests_require=['blinker', 'django==1.3']
tests_require=['blinker', 'django>=1.3']
)

View File

@ -997,10 +997,16 @@ class FieldTest(unittest.TestCase):
mongodb = Product(name='MongoDB', company=ten_gen)
mongodb.save()
me = Product(name='MongoEngine')
me.save()
obj = Product.objects(company=ten_gen).first()
self.assertEqual(obj, mongodb)
self.assertEqual(obj.company, ten_gen)
obj = Product.objects(company=None).first()
self.assertEqual(obj, me)
def test_reference_query_conversion(self):
"""Ensure that ReferenceFields can be queried using objects and values
of the type of the primary key of the referenced object.