Retrieve the same values ​whose data is there or exists and not the rest.In django

人走茶凉 提交于 2021-01-07 02:56:27

问题



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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!