John Smith John Smith - 6 months ago 47
Python Question

Ordering users by date created in django admin panel

How do you order users in the django admin panel so that upon display they are ordered by date created? Currently they are listed in alphabetical order

I know that I can import the

model via:
from django.contrib.auth.models import User

How do I go about doing this?


To change the default ordering of users in admin panel you can subclass the default UserAdmin class. In your applications's

from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

class MyUserAdmin(UserAdmin):
    # override the default sort column
    ordering = ('date_joined', )
    # if you want the date they joined or other columns displayed in the list,
    # override list_display too
    list_display = ('username', 'email', 'date_joined', 'first_name', 'last_name', 'is_staff')

# finally replace the default UserAdmin with yours, MyUserAdmin)

For more information refer to the documentation.