I want to get a list of users that have provided an email in my database using Django.
This is my query:
list(App.objects.exclude(admins__email__exact='').values('admins__email'))
which strangely excludes everything and gives: []
although when I run: list(App.objects.all().values('admins__email'))
i can see a list of user emails and NOT all of them are empty:
[{'admins__email': '[email protected]'},
{'admins__email': ''},
{'admins__email': ''},
{'admins__email': ''},
{'admins__email': '[email protected]'},
{'admins__email': '[email protected]'},
{'admins__email': ''},
...]
i expect to get this list:
[{'admins__email': '[email protected]'},
{'admins__email': '[email protected]'},
{'admins__email': '[email protected]'}]
ps: somehow I can get the correct list with list(User.objects.exclude(email__exact='').values('email'))
but in this context, I need to apply some filters to my App
and therefore I need to get the first query to work.
2
Answers
I finally got it working this way:
although I find it odd that
__exact=''
is not working. seems like a Django bug to me.Try this