代码之家  ›  专栏  ›  技术社区  ›  Yunti

django allauth扩展用户模型-使用默认注册表单

  •  0
  • Yunti  · 技术社区  · 8 年前

    我正在使用django allauth,并用下面的模型扩展了用户模型。 accounts/signup/ 那么表单中出现的字段只有默认用户模型中的字段。allauth是否需要自定义注册表单来显示其他字段?

    模型。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
    

    相关设置:

    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'
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   Yunti    7 年前

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