Filter Combined Date And Time In Django
I have a model with separated date and time, I want to filter for future events and ended up writing this, which is not cool. Is there a more nicer way? Can I use combine() and min
Solution 1:
Lookup using Q objects:
from django.db.models import Q
today = datetime.now().date()
now = datetime.now().time()
future_events = CauseEvent.objects.filter(cause=instance) \
.exclude(Q(date__lt=today) |
Q(date=today, time__lt=now))
Post a Comment for "Filter Combined Date And Time In Django"