In my Django project I have created an app called Deportes
(added in the settings.py
). Entering the Django admin in the Sports area shows the added sports listed. I would like this list to be displayed in alphabetical order.
The code I use inside models.py
is very simple:
def __unicode__(self):
return self.nombre_deporte_es
One option is, if you want the order to apply at the system level and for all cases, you have to define this order in
Meta
your model, specifically the optionordering
:The above form would apply for ascending name order. For descending order you can use:
If it is not the case that you want this order to apply system-wide and you only want it to apply to your admin, you would have to make some changes to your
admin.py
and edit the functionget_queryset
: