I get a queryset for a certain model and I’d like to get its complement, i.e. all instances of that model that are not in the aforementioned queryset.
How can I do that?
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.
Short solution
More DRY solution
However, if you want to use the logic many times, I would suggest to encapsulate it in a method. Here is an example I personnaly used in a custom queryset: