A
A
Andrey Kirdyashkin2020-12-17 10:03:40
Django
Andrey Kirdyashkin, 2020-12-17 10:03:40

How to return default User password display in Django admin?

Good afternoon

Added additional fields for the user through AbstractUser

models.py

class User(AbstractUser):
    llcname = models.CharField('Наименование организации', max_length=50, blank=True)
    llctin = models.CharField('ИНН', max_length=12, blank=True)
    llccity = models.CharField('Город', max_length=30, blank=True)
    llctel = models.CharField('Телефон', max_length=30, blank=True)


I brought these additional fields in the admin panel via add_fields, but it doesn't look very good. All in different places.
I decided to display everything differently and there is a problem, the password is displayed in the usual input (As well as through add_fields).
admin.py

class UserAdmin(admin.ModelAdmin):
    list_display = ('username', 'last_name', 'first_name', 'llcname', 'llctin', 'is_active')
    fields = (
        'username',
        ('last_name', 'first_name'), 
        ('llcname', 'llctin'), ('llctel', 'llccity'), 
        'email', 'password',
        ('is_superuser', 'is_staff', 'is_active'),
        ('date_joined', 'last_login'),
        'groups'
    )

admin.site.register(User, UserAdmin)


How to return the standard display of the password and a link to change it, while maintaining the normal and convenient arrangement of the fields?
django standard

5fdb10e6ac8a0041460077.png

What happened

5fdb110ac845f530984545.png

Thanks a lot in advance ☺️

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Kirdyashkin, 2021-06-03
@ANDYNEI

https://github.com/django/django/blob/master/djang...

M
mr_forlife, 2021-05-29
@mr_forlife

In the admin.py file, inherit the UserAdmin class from the UserAdmin module django.contrib.auth.admin

admin.py

from django.contrib.auth.admin import UserAdmin

class UserAdmin(UserAdmin):
    list_display = ('username', 'last_name', 'first_name', 'llcname', 'llctin', 'is_active')
    fields = (
        'username',
        ('last_name', 'first_name'), 
        ('llcname', 'llctin'), ('llctel', 'llccity'), 
        'email', 'password',
        ('is_superuser', 'is_staff', 'is_active'),
        ('date_joined', 'last_login'),
        'groups'
    )

admin.site.register(User, UserAdmin)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question