I am now able to display the item I want using the list_display[]
but I would like them to displayed alphabetically. How do you make that the list_display
is ordered alphabetically?
Example in Django-admin:
class PersonAdmin(admin.ModelAdmin):
list_display = ('upper_case_name',)
def upper_case_name(self, obj):
return ("%s %s" % (obj.first_name, obj.last_name)).upper()
upper_case_name.short_description = 'Name'
How to alter this to display alphabetically? Need some help on this...
Set ModelAdmin.ordering = ('foo', )
to order your admin.
Example
class TeamRoleAdmin(admin.ModelAdmin):
""" Team Role admin view with modifications """
model = TeamRole
ordering = ('team', 'role', 'user')
list_display = ['id', 'user', 'team', 'role']
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.ordering
Modify global model meta class, override ModelAdmin.queryset, there are many ways but you most likely want the Admin ordering.
In your models Meta
you can specify ordering = ['first_name', 'last_name']
.
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