MongoEngine/mongoengine — pull request #264 by yograterol (2013-04-01 00:10:46+00:00)
Title: Fix problem with db_field in distinct()

Hello,

I Fix problem with db_field in distinct(), Issue: https://github.com/MongoEngine/mongoengine/issues/260

mongoengine/queryset.py

(-) return self._dereference(self._cursor.distinct(field), 1,
(-) name=field, instance=self._document)
(+)
(+) try:
(+) field_document = QuerySet._lookup_field(self._document, field)
(+) if field_document:
(+) field = field_document[0].db_field
(+) finally:
(+) return self._dereference(self._cursor.distinct(field), 1,
(+) name=field, instance=self._document)