Django order_by query set, ascending and descending

1.1K    Asked by Chandralekhadebbie in Salesforce , Asked on Jul 9, 2021

 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 want to filter from descending all the Reserved by check_in date. How django order by desc ?

 

Answered by Dorine Hankey

You can use the below-mentioned command for Django order_by query set, ascending and descending:-

  Reserved.objects.filter(client=client_id).order_by('-check_in')

Or

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')

Your Answer

Interviews

Parent Categories