检索数据存在或存在的相同值,而不是 rest.In django

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


我想要一个在数据库或行中没有任何空值的数据。 我在我的代码中是这样写的。

faq = FAQ.objects.values('question','answer','field_id')

这是我终端的输出

{'question': None, 'answer': None, 'field_id': None}
{'question': 'Test question', 'answer': '<p>Testsaddsf description</p>\r\n', 'field_id': 'TestTest'}

我不想要 None 值数据。

您可以使用 __isnull lookup [Django-doc] 进行过滤:

faq = FAQ.objects.filter(
    question<b>__isnull=False</b>,
    answer<b>__isnull=False</b>,
    field_id<b>__isnull=False</b>
).values('question','answer','field_id')

因此,这将仅包括 questionanswerfield_id 中的 none 为 NULL/None 的记录。