【发布时间】:2012-01-15 06:47:47
【问题描述】:
我正在使用django-userena。我有一个名为UserProfile 的模型。我在注册表单中添加了额外的字段。并且这些字段正确显示,但未保存数据。我也想将一些字段数据保存到另一个模型(Business)中。例如,我有两个字段,例如 contact 和 business。我希望联系人字段将转到UserProfile 模型和business 字段将转到Business Model。任何线索?谢谢
这是我的代码
class SignupFormExtra(SignupForm):
address = forms.CharField(label=_(u'Address'),max_length=30,required=False)
contact = forms.CharField(label=_(u'Contact'),max_length=30,required=False)
business = forms.CharField(label=_(u'Business Name'),max_length=30,required=False)
def save(self):
"""
Override the save method to save the first and last name to the user
field.
"""
user_profile = super(SignupFormExtra, self).save(commit=False)
user_profile.address = self.cleaned_data['address']
user_profile.contact = self.cleaned_data['contact']
user_profile.business = self.cleaned_data['business']
user_profile.save()
return user_profile
更新:我将这些值存储在用户实例上...我想将它们存储在 Profile 模型上——一个绑定到用户的实例
【问题讨论】:
-
你用form的clean方法试过了吗?
标签: python django registration