我使用django向导来拥有多个表单(最后会有几页表单)。
我有一个自定义用户模型,我已将注册分成几个模型(使用Meta,字段)。但是我不清楚django向导如何设置done
方法来将表单中的所有数据保存到单个用户实例中?
models.py
class User(AbstractUser):
name = models.CharField(_("Name of User"), blank=True, max_length=255)
account_name = models.CharField(max_length=255)
account_number = models.IntegerField()
def __str__(self):
return self.username
forms.py
class SignupForm(allauthforms.SignupForm):
first_name = forms.CharField(max_length=30)
last_name = forms.CharField(max_length=30)
class UserAccountForm(forms.ModelForm):
class Meta:
model = User
fields = ['account_name',
'account_number',
]
views.py
SIGNUP_FORMS = [
('signup', SignupForm),
('direct_debit', UserDirectDebitForm),
]
TEMPLATES = {
'signup': 'account/signup.html',
'direct_debit': 'site/directdebit.html',
}
class SignupWizard(SessionWizardView):
def get_template_names(self):
return [TEMPLATES[self.steps.current]]
def done(self, form_list, **kwargs):
xxxxxxx
return HttpResponseRedirect(reverse('home'))
signup_view = SignupWizard.as_view(SIGNUP_FORMS)