order_by() method in Django

Order results by different fields using the order_by() method of the manager. For Ex:, you can retrieve all objects ordered by their post_name, as follows:

  • Posts.objects.order_by('post_name')

Ascending order is implied. You can indicate descending order with a negative sign prefix.

  • Posts.objects.order_by('-post_name')

Comments

Popular posts from this blog

Internationalization (Language Setting) in Django

reverse_lazy() Method in Django

CharFilter in Django