How can I order by descending my query set in django by date?
Reserved.objects.all().filter(client=client_id).order_by(\'check_in\')
I just
for ascending order:
Reserved.objects.filter(client=client_id).order_by('check_in')
for descending order:
1. Reserved.objects.filter(client=client_id).order_by('-check_in')
or
2. Reserved.objects.filter(client=client_id).order_by('check_in')[::-1]
Reserved.objects.filter(client=client_id).earliest('check_in')
Or alternatively
Reserved.objects.filter(client=client_id).latest('-check_in')
Here is the documentations for earliest() and latest()
This is working for me.
latestsetuplist = SetupTemplate.objects.order_by('-creationTime')[:10][::1]
Ascending order
Reserved.objects.all().filter(client=client_id).order_by('check_in')
Descending order
Reserved.objects.all().filter(client=client_id).order_by('-check_in')
-
(hyphen) is used to indicate descending order here.
67
Reserved.objects.filter(client=client_id).order_by('-check_in')
'-' is indicates Descending order and for Ascending order just give class attribute