Filtering QuerySets in Django work like the following:
Entry.objects.filter(year=2006)
How can I use filter to find all entries which does not have year 2006? Something similar to the following sql:
SELECT *
FROM entries
WHERE not year = 2006
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think you are looking for the
exclude()method: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: