Search code examples
djangodjango-allauth

django allauth extended user model - Using default signup form


I'm using django-allauth and have extended the user model with the model below. However when I go to accounts/signup/ then the only fields that appear in the form are those in the default user model. Does allauth require a custom signup form to display the other fields?

models.py

class User(AbstractUser):
    MR = 'Mr'
    MRS = 'Mrs'
    MISS = 'Miss'
    MS = 'Ms'
    DR = 'Dr'
    SIR = 'Sir'
    PROF = 'Prof'
    REV = 'Rev'
    TITLE_CHOICES = (
        (MR, 'Mr'),
        (MRS, 'Mrs'),
        (MISS, 'Miss'),
        (DR, 'Dr'),
        (SIR, 'Sir'),
        (PROF, 'Prof'),
        (REV, 'Rev'),
    )
    title = models.CharField(max_length=5, null=True, choices=TITLE_CHOICES)
    date_of_birth = models.DateField()
    primary_phone = PhoneNumberField()


    def __str__(self):
        return self.username

Relevant settings:

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'allauth.account.auth_backends.AuthenticationBackend',
)

ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = False
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'  
ACCOUNT_ALLOW_REGISTRATION = env.bool('DJANGO_ACCOUNT_ALLOW_REGISTRATION', default=True)   

ACCOUNT_FORMS = {'login': 'switcher5.users.forms.LoginForm',
                 # 'signup': 'switcher5.users.forms.ProfileForm', 
                 # no longer using a onetoonefield profile model
                 'reset_password': 'switcher5.users.forms.ResetPasswordForm'}

ACCOUNT_ADAPTER = 'switcher5.users.adapter.AccountAdapter'
SOCIALACCOUNT_ADAPTER = 'switcher5.users.adapter.SocialAccountAdapter'


AUTH_USER_MODEL = 'users.User'

Solution

  • Looking at the source code, allauth Signup form doesn't use all fields that are present in the user model defined in settings. But only username, email and password as setup by the allauth settings.

    To use additional fields in a custome user model. You need to subclass the Signup form from all auth and change settings to use that:

    eg

    ACCOUNT_FORMS = {'login': 'switcher5.users.forms.LoginForm',
                     'signup': 'switcher5.users.forms.ProfileForm',
                     'reset_password': 'switcher5.users.forms.ResetPasswordForm'}