Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django object multiple exclude()

Is there a way to do a query and exclude a list of things, instead of calling exclude multiple times?

like image 673
Johnd Avatar asked May 26 '09 20:05

Johnd


People also ask

What is exclude in Django?

The exclude() method from the QuerySet class returns all objects that do not match the given keyword arguments. So whatever data matches the parameter that is passed into the exclude() method will be excluded from the returned QuerySet.


1 Answers

Based on your reply to Ned, it sounds like you just want to exclude a list of tags. So you could just use the in filter:

names_to_exclude = [o.name for o in objects_to_exclude]  Foo.objects.exclude(name__in=names_to_exclude) 

Does that do what you want?

like image 90
Daniel Roseman Avatar answered Oct 13 '22 15:10

Daniel Roseman