简体   繁体   English

如何在django中的算术查询中包含空值

[英]How can I include null values in arithmetic query in django

I have the field called surface_area which is null and float. 我有一个名为surface_area ,它是null和float。

Now I can't set that to default 0 because 0 means something else in business rules. 现在我无法将其设置为default 0因为0表示业务规则中的其他内容。

I want to perform query like this 我想执行这样的查询

Room.objects.filter(surface_area__lte=40)

But this does not include null values. 但这不包括空值。

How can I include null values as well for lte queries 如何为lte查询包含空值

You can check for null values like: 您可以检查以下null值:

Room.objects.filter(surface_area__isnull=True)

And combine that with your lte : 并将其与你的lte结合起来:

from django.db.models import Q
Room.objects.filter( Q(surface_area__lte=40) | Q(surface_area__isnull=True) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 psycopg 中使用 SELECT 查询查找空值? - How can I find null values with SELECT query in psycopg? 如何在Django查询参数中使用复选框选择的值? - How can I use checkbox selected values in Django query parameters? 如何使用Django检索多个查询参数值? - How can I retrieve multiple query parameter values with Django? 如何使用值列表过滤Django查询? - How can I filter a Django query with a list of values? 如何针对自定义值列表订购Django查询? - How can I order a Django query against a custom list of values? 如何查询具有 Foreign 和 OneToOneFields 的 Django 模型的字段值 - How Can I query Django Models with Foreign and OneToOneFields for Field Values 在 Django 中,我如何理解 include() 函数? - In Django, how can I understand include() function? 如何在 {% include %} 标签 django 中包含我的参数? - How can I include my argument in {% include %} tag django? 在 SQLAlchemy 中,如何过滤我的查询以仅包含具有非空 jsonb 列值的行? - In SQLAlchemy how can I filter my query to only include rows with non-empty jsonb column values? 如何在Django 1.8中创建可重用的函数以使用多个null值实施“ unique_together”? - How can I create a reusable function to enforce “unique_together” in Django 1.8 with multiple null values?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM