If I want to filter "greater than or equal to", I can use gte
:
MyModel.objects.filter(mydatetimefield__gte=mydate)
Likewise, if I want to filter "is none/null", I can use isnull
:
MyModel.objects.filter(mydatetimefield__isnull=mydate)
How can I combine these to filter for "greater than or equal to or is null", so the above filter would return both objects if i) mydatetimefield >= mydate
, and ii) mydatetimefield == null
?
you use
Q
statements to performOR
logic与Willem Van Onsems的精神保持一致
You can use
Q
objects [Django-doc], and use a bitwise or (|
) operator to specify a condition that should satisfiy one of the two subconditions:or you can negate the
__lt
lookup: