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

时间:2017-09-08 21:20:01

标签: django django-allauth

我正在使用django-allauth,并使用下面的模型扩展了用户模型。 但是,当我转到accounts/signup/时,表单中出现的唯一字段是默认用户模型中的字段。 allauth是否需要自定义注册表单才能显示其他字段?

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

相关设置:

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 个答案:

答案 0 :(得分:0)

查看源代码,allauth注册表单不会使用设置中定义的用户模型中存在的所有字段。但只有allauth设置设置的用户名,电子邮件和密码。

在客户用户模型中使用其他字段。您需要从所有身份验证子类化注册表单并更改设置以使用:

例如

data Move f where
    Move :: Under (Zipped g) f -> Int -> Move f

movesZipped :: [Move f] -> f a -> f a
movesZipped ms z = foldr (\(Move u n) -> moveUnder u n) z ms

rightTwoUpOne = movesZipped [Move Over 2, Move (Under Over) (-1)]