django-nonrel/mongodb-engine — pull request #120 by dconlon (2012-03-26 12:50:00+00:00)
Title: Implementation of distinct()

Hi All,

I saw that distinct() was added (https://github.com/django-nonrel/mongodb-engine/commit/efcebec036d00b2e3da76f685329e6e6650bcc8f) but did not have cause to use it until today.

It seemed possible to chain distinct() with filter():

```python
from django_mongodb_engine.contrib import MongoDBManager

class FooModel(models.Model):
...
objects = MongoDBManager()

FooModel.objects.filter(filters).distinct(fields)
```
in that code of the above form executes without error.

However the filters are ignored as distinct() is called on the pymongo Collection, not on the pymongo Cursor from the query result.

I'm not sure what the intention was with distinct() but I lost several hours to this today and wondered whether it should either be amended to work with filter() or raise an exception when called on a QuerySet. Either could help future hapless coders like me.

I've had a go at making it work with filter() and welcome your feedback.

Dan