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.
When we read the data from the model, Django returns queryset. Django has order_by method to sort the queryset in ascending and descending order. You can order the queryset on any field.
This answer Django Datetime Field Query - Order by Time/Hour suggests that I use '__day' with my date_modified as in: Article. objects. filter().
Django order by lets you specify how your query results should be ordered. Here's an example where we will order by the author's name: class Author(models.Model): name = models.CharField() Author.objects.order_by("name")
If you are just doing two simple filter operations, then you're correct that order doesn't matter, but be careful. There are examples of when the order of your queryset methods do matter: https://docs.djangoproject.com/en/dev/topics/db/aggregation/#order-of-annotate-and-filter-clauses.
Reserved.objects.filter(client=client_id).order_by('-check_in')
Notice the -
before check_in
.
Django Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With