change user creation form shown in Django admin

123 views
Skip to first unread message

Anil Felipe Duggirala

unread,
Jan 7, 2022, 1:04:29 PM1/7/22
to Django users
hello,
I am using a custom user model.
I have created a form that includes an extra field:

## /users/forms.py

class CustomUserCreationForm(UserCreationForm):

class Meta(UserCreationForm):
model = CustomUser
fields = UserCreationForm.Meta.fields + ('phoneno',)

I am using this form successfully on my user facing signup page (I get username, phoneno and password).
However I would like to achieve the same within the Django admin (have the 'phoneno' field shown).
I have tried to achieve this doing:

## /users/admin.py

class CustomUserAdmin(UserAdmin):
add_form = CustomUserCreationForm
form = CustomUserChangeForm
model = CustomUser
list_display = ['email', 'username', 'phoneno', 'is_staff', ]

However, in the Django admin, when adding a new user, I still face the default form which only has the username and password (no 'phoneno')

thanks for your help.


Anil F
Reply all
Reply to author
Forward
0 new messages