Take the 2-minute tour ×

Filtering QuerySets in Django work like the following:


How can I use filter to find all entries which does not have year 2006? Something similar to the following sql:

FROM entries
WHERE not year = 2006
share|improve this question
add comment

1 Answer

up vote 20 down vote accepted

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')
share|improve this answer
add comment

Your Answer


