Django:如何匹配数据库中的空值

发布于 2024-10-04 23:01:16 字数 150 浏览 0 评论 0原文

通过使用 django ORM:如何匹配数据库中的结果不为空?

example_objects = Example.objects.filter(field !=null)

我不确定如何编写该过滤器来获取所有非空记录。

By using django ORM: How to match the result in database is NOT null?

example_objects = Example.objects.filter(field !=null)

I'm not sure about how to write that filter to get all non-null records.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

荆棘i 2024-10-11 23:01:16

我认为您正在寻找:

Example.objects.filter(field__isnull=False)

或:

Example.objects.exclude(field__isnull=True)

I think you're looking for either:

Example.objects.filter(field__isnull=False)

or:

Example.objects.exclude(field__isnull=True)
秋叶绚丽 2024-10-11 23:01:16
example_objects = Example.objects.exclude(field=None)
example_objects = Example.objects.exclude(field=None)
雪若未夕 2024-10-11 23:01:16

怎么样?

example_objects = Example.objects.exclude(field =null)

how about

example_objects = Example.objects.exclude(field =null)?

不爱素颜 2024-10-11 23:01:16

使用 NullBooleanField 如下:

happy = models.NullBooleanField(null=True, blank=True)

Use NullBooleanFeild as below::

happy = models.NullBooleanField(null=True, blank=True)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文