6
Get the today’s date from datetime.date.today()
and use gt
and lt
:
import datetime
today = datetime.date.today()
Event.objects.filter(start__lt=today, end__gt=today)
This would filter objects where start date is less than today and end date is greater than today.
1
You can use combine method of datetime module:
import datetime
today = datetime.datetime.today()
Event.objects.filter(start__gte=datetime.datetime.combine(today, datetime.time.min),
end__lte=datetime.datetime.combine(today, datetime.time.max))
Source:stackexchange.com