Fixed querying string versions of ObjectIds issue with ReferenceField (#307)

This commit is contained in:
Ross Lawley
2013-05-07 11:54:47 +00:00
parent 7cde979736
commit 9dfee83e68
4 changed files with 49 additions and 4 deletions

View File

@@ -854,7 +854,7 @@ class ReferenceField(BaseField):
return document.id
return document
elif not self.dbref and isinstance(document, basestring):
return document
return ObjectId(document)
id_field_name = self.document_type._meta['id_field']
id_field = self.document_type._fields[id_field_name]

View File

@@ -544,8 +544,9 @@ class QuerySet(object):
return c
def select_related(self, max_depth=1):
"""Handles dereferencing of :class:`~bson.dbref.DBRef` objects to
a maximum depth in order to cut down the number queries to mongodb.
"""Handles dereferencing of :class:`~bson.dbref.DBRef` objects or
:class:`~bson.object_id.ObjectId` a maximum depth in order to cut down
the number queries to mongodb.
.. versionadded:: 0.5
"""