DEV Community

Discussion on: Customizing Django Authentication using AbstractBaseUser

Collapse
 
rhlpnd89 profile image
rahul pandey • Edited

Hi , thanks for sharing this unique post. Just one thing I want to ask is about form section-
You have created 2 forms- Usrcreationform and registration form . Both are inherited from forms.ModelForm . Why you have written 2 different forms and used only 1? I am asking this as I want to add "confirm password field" in registration form that you have written in User Creation form.

Collapse
 
joshwizzy profile image
Joshua Masiko

Hi Rahul,

RegistrationForm is used by the public-facing RegistrationView.
I use a separate form because it can include registration specific code that is not needed in the backend User Creation process (e.g captcha field, label, help text).
You can customize it to fit your requirements.

UserCreationForm and UserChangeForm are used by the auto-generated Django Admin backend.
The need to be rewritten since they are tied to the inbuilt User model as explained here

The relevant code is in accounts/admin.py:

...
class AccountAdmin(BaseUserAdmin):
    form = UserChangeForm
    add_form = UserCreationForm
...