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 User
model via: from django.contrib.auth.models import User
How do I go about doing this?
To login to the site, open the /admin URL (e.g. http://127.0.0.1:8000/admin ) and enter your new superuser userid and password credentials (you'll be redirected to the login page, and then back to the /admin URL after you've entered your details).
One of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick, model-centric interface where trusted users can manage content on your site. The admin's recommended use is limited to an organization's internal management tool.
To change the default ordering of users in admin panel you can subclass the default UserAdmin class. In your applications's admin.py
:
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
admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)
For more information refer to the documentation.
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