问题
I want to have a data that does not have any empty value in database or in row. I wrote like this in my code.
faq = FAQ.objects.values('question','answer','field_id')
this the output in my terminal
{'question': None, 'answer': None, 'field_id': None}
{'question': 'Test question', 'answer': '<p>Testsaddsf description</p>\r\n', 'field_id': 'TestTest'}
i don't want None
value data.
回答1:
You can filter with the __isnull lookup [Django-doc]:
faq = FAQ.objects.filter(
question__isnull=False,
answer__isnull=False,
field_id__isnull=False
).values('question','answer','field_id')
This will thus only include records where none of question
, answer
or field_id
are NULL
/None
.
来源:https://stackoverflow.com/questions/65547680/retrieve-the-same-values-whose-data-is-there-or-exists-and-not-the-rest-in-djan