检索存在或存在数据而不是其余数据的相同值. [英] Retrieve the same values ​whose data is there or exists and not the rest.In django

查看:49
本文介绍了检索存在或存在数据而不是其余数据的相同值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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')

这是我终端中的输出

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

我不想要 None 值数据.

推荐答案

您可以使用 __ isnull 查找[Django-doc] :

faq = FAQ.objects.filter(
    question__isnull=False,
    answer__isnull=False,
    field_id__isnull=False
).values('question','answer','field_id')

因此,这将仅包括其中 question answer field_id 都不是 NULL /无.

This will thus only include records where none of question, answer or field_id are NULL/None.

这篇关于检索存在或存在数据而不是其余数据的相同值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆