I have an event object that has from_date as a field that represents when the event starts. I want to do this to find an upcoming event, and then find the next upcoming events that are still within a month. Here are two questions that I still have, is there a way to combine them?
today = datetime.date.today() date = Event.objects.filter( status='P', # Published status pub_date__lte=today, # Published after today, or today from_date__gte=today, # Starting next ).order_by('from_date').only('from_date')[:1][0].from_date events = Event.objects.filter( # Published after today, with a published status, and start today or later pub_date__lte=today, from_date__gte=today, status='P', # We're only going to show one month at a time. from_date__month=date.month, from_date__year=date.year, )
source share