Is there a way to do a query and exclude a list of things, instead of calling exclude multiple times?
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With