0

我正在使用 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 注册的最佳方法是什么?谢谢!

4

0 回答 0