I have the field called surface_area
which is null and float.
Now I can't set that to default 0
because 0 means something else in business rules.
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
You can check for null
values like:
Room.objects.filter(surface_area__isnull=True)
And combine that with your lte
:
from django.db.models import Q
Room.objects.filter( Q(surface_area__lte=40) | Q(surface_area__isnull=True) )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.