Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Django Users List Display

Tags:

django

admin

I am trying to change the Users view in Django Admin to show different fields (now it shows by default: username, email address, first name, last name, staff status) I have tried this in the admin.py file:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
# Register your models here.


UserAdmin.list_display = ['email', 'first_name', 'last_name', 'is_active', 'last_login']

admin.site.unregister(User)
admin.site.register(User, UserAdmin)

However I cannot get my admin Users view to change. Is there anything else I need to do? I am using Django 2.0

like image 750
Hugo Alain Oliva Avatar asked May 18 '18 11:05

Hugo Alain Oliva


1 Answers

Quite simply: define your own UserAdmin:

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

class MyUserAdmin(admin.ModelAdmin):
    list_display = ['email', 'first_name', 'last_name', 'is_active', 'last_login']

admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)
like image 169
bruno desthuilliers Avatar answered Nov 15 '22 08:11

bruno desthuilliers