Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin ordering in reverse

Tags:

python

django

In admin.py:

class ObjectAdmin(admin.ModelAdmin):
    ordering = ['order']

Is there a way to order in reverse?

like image 231
bArmageddon Avatar asked Dec 29 '13 14:12

bArmageddon


People also ask

How do I sort fields in Django admin?

You can order the fields as you wish using the ModelAdmin. fields option. The order of fields would depend on the order in which you declare them in your models. So alternatively you could order the fields in the way you would want them to show in the admin.

Is Django's admin interface customizable if yes then how?

The Django framework comes with a powerful administrative tool called admin. You can use it out of the box to quickly add, delete, or edit any database model from a web interface. But with a little extra code, you can customize the Django admin to take your admin capabilities to the next level.


1 Answers

Prepend - to order descending.

class ObjectAdmin(admin.ModelAdmin):
    ordering = ['-order']
    #            ^

See Model Meta options | Django documentation - ordering.

like image 77
falsetru Avatar answered Oct 07 '22 03:10

falsetru