[Answered ]-Django querySet order by date closest to today

1👍

You can filter the Events with Event.objects.filter(event_date__gte=today) to retrieve only Events that start today or in the future:

from django.utils.timezone import now

def dashboard_view(request):
    today = now().date()
    game_list=Game.objects.all()
    event_list = Event.objects.filter(event_date__gte=today).order_by('event_date')
    
    return render(request, 'dashboard.html', {'game_list':game_list, 'event_list': event_list})

Leave a comment