- Django 2 by Example
- Antonio Melé
- 47字
- 2021-06-25 21:19:01
Using order_by()
You can order results by different fields using the order_by() method of the manager. For example, you can retrieve all objects ordered by their title, as follows:
Post.objects.order_by('title')
Ascending order is implied. You can indicate descending order with a negative sign prefix, like this:
Post.objects.order_by('-title')