[Fixed]-In Django QuerySet, how do I do negation in the filter?


I think you are looking for the exclude() method:

>>> Entry.objects.exclude(year=2006)

Will return all Entry objects that are not in the year 2006.

If you wish to further filter the results, you can chain this to a filter() method:

>>> Entry.objects.exclude(year=2006).filter(field='value')

Leave a comment