python - Django Select Query获取带条件的多列

标签 python mysql django

我有一个表/模型“ABC”,它有两个列字段“A”和“B”。我想查询上表如下:

select A, B from ABC where B is not null;

我能做到

select A, B from ABC;

但我不知道如何引入空检查条件。 我尝试了以下但没有成功:

ABC.objects.values('A', 'B')  # which is getting all the tuples including null valued 'B' column
ABC.objects.values('A', 'B', 'B__isnull=False')  # which is incorrect
ABC.objects.values('A', 'B__isnull=False')  # which is incorrect again.

有人可以提供我可以使用的正确格式/查询吗?

谢谢。

最佳答案

没关系,我明白了:)

ABC.objects.values('A', 'B').exclude(B__isnull=True)

关于python - Django Select Query获取带条件的多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30087536/

相关文章:

python - pd.date_range() 函数中是否有组合频率参数?

django - Wagtail:我可以使用 API 来获取页面的只读草稿以供审核吗?

python - 将文本和图像添加到图像的简单方法(对于 fb 应用程序) - PIL 在依赖性方面是 hell

c++ - 在 linux 上检测绑定(bind)挂载

python - 使用 Tkinter 中的消息框显示哪个字段为空

mysql - Memcache 与内存中的 MySQL

mysql - [42S22][1054] 'where clause' 中的未知列

php - 将表值传递到另一个页面进行 SQL 查询

python - 为什么 Django 和 CherryPy 本身不支持基于 HTTP 动词的调度?

django - 如何在 nginx 后面的 suburl 下部署 django