Added support for distinct and db_alias (MongoEngine/mongoengine#59)

This commit is contained in:
Ross Lawley
2012-08-07 10:04:05 +01:00
parent 95b1783834
commit 475488b9f2
5 changed files with 33 additions and 6 deletions

View File

@@ -34,7 +34,9 @@ class DeReference(object):
doc_type = None
if instance and instance._fields:
doc_type = instance._fields[name].field
doc_type = instance._fields[name]
if hasattr(doc_type, 'field'):
doc_type = doc_type.field
if isinstance(doc_type, ReferenceField):
doc_type = doc_type.document_type

View File

@@ -1168,7 +1168,8 @@ class QuerySet(object):
.. versionchanged:: 0.5 - Fixed handling references
"""
from dereference import DeReference
return DeReference()(self._cursor.distinct(field), 1)
return DeReference()(self._cursor.distinct(field), 1,
name=field, instance=self._document)
def only(self, *fields):
"""Load only a subset of this document's fields. ::