I want to filter a table objects using a DateTimeField => last_user_action_time, this field can be null so I need the cases where its null to be included in the result.
Here is what I tried:
notification_objects = SinglePushNotification.objects.filter(
last_user_action_time__lte=day_start,
last_user_action_time__isnull=True,
).select_related("customer")
This return an empty querySet knowing there is objects where null=True
>Solution :
Sounds like you need to use an or query, in your attempt you are checking that both conditions are true: field is null and date is less than start (impossible case).
Try an or like so:
from django.db.models import Q
notification_objects = SinglePushNotification.objects.filter(
Q(last_user_action_time__lte=day_start) |
Q(last_user_action_time__isnull=True)
).select_related("customer")