I have a query and i want to exclude null companies as well as specific user email.
Demo.objects.all().exclude(company__isnull=True, email="[email protected]")
but seems like above exclude does not work with multiple arguments, my return queryset has email="[email protected]" in it.
If i try above query with single arguments, it works. but not working with multiple arguments. Anyone has any idea how to pass multiple arguments in django exclude ?
Thanks
You can do this, but then you say exclude all
Demos that havecompany__isnull=True, and asemail'[email protected]'. This thus means that if only one of the two conditions is met, it is not excluded.You can work with
Qobjects, like:But it is likely more readable with:
this will thus exclude items for which
companyisNULLand exclude items for whichemailis'[email protected]'. So here we exclude it from the moment at least one condition is satisfied.