Django注册Redux:添加字段到用户配置文件错误

时间:2015-11-01 19:53:49

标签: django registration redux

我正在尝试向用户添加一些扩展字段,但它只保存用户信息,但不保存新表中的额外字段。

这是模型:

class UserProfile(models.Model):
    field = models.CharField(max_length=3)
    user = models.OneToOneField(User, unique=True)

这里的表格是:

class UserProfileRegistrationForm(RegistrationFormUniqueEmail):
    field = forms.CharField()

regbackend.py

class UserRegistrationView(RegistrationView):

    form_class = UserProfileRegistrationForm

    def register(self, request, form_class):
        new_user = super(UserRegistrationView, self).register(request, form_class)
        new_user.field = form_class.cleaned_data['field']
        new_user.save()
        user_profile = new_user.get_profile()
        user_profile.field = form_class.cleaned_data['field']
        user_profile.save()
        return user_profile

和urls.py

urlpatterns = patterns('',
    url(r'^$', index_view),
    url(r'^accounts/register/$', regbackend.UserRegistrationView.as_view(), name='registration_register'),
    url(r'^accounts/', include('registration.backends.default.urls')),
)

知道问题是什么吗?

0 个答案:

没有答案