Friday, January 7, 2022

change user creation form shown in Django admin

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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aa199cca-44cb-4ca0-8806-6731e6d77d4b%40www.fastmail.com.

No comments:

Post a Comment