我正在使用django注册模块并尝试添加自定义字段:
RegistrationForm.base_fields.update(FarmerForm.base_fields)
class CustomRegistrationForm(RegistrationForm):
def save(self, profile_callback=None):
user = super(CustomRegistrationForm, self).save(profile_callback=None)
f = Farmer(user=user)
f.farm = self.cleaned_data['farm']
f.produce = self.cleaned_data['produce']
f.produce_price = self.cleaned_data['produce_price']
f.save()
出于某种原因, 以下部分:
f = Farmer(user=user)
f.farm = self.cleaned_data['farm']
f.produce = self.cleaned_data['produce']
f.produce_price = self.cleaned_data['produce_price']
f.save()
不执行。
我做错了什么?
然后将自定义字段添加到django注册的最佳方法是什么?谢谢!