7
class RegistrationFormPreview(FormPreview):
preview_template = 'workshops/workshop_register_preview.html'
form_template = 'workshops/workshop_register_form.html'
def done(self, request, cleaned_data):
# Do something with the cleaned_data, then redirect
# to a "success" page.
# data = request.POST.copy()
# data['user_id'] = u'%s' % (request.user.id)
# cleaned_data['user'] = u'%s' % (request.user.id)
#f = self.form(cleaned_data)
#f = self.form(data)
#f.user = request.user
f = self.form(request.POST)
f.save()
pdb.set_trace()
return HttpResponseRedirect('/register/success')
ご覧のとおり、いくつかの方法を試しましたが、コメントアウトされています。タスクは明らかに単純です:要求のフォームから保存する前にユーザーを追加して保存します。Djangoフォームのプレビュー - 保存する前にフォームにユーザーを追加する
ここで受け入れられている作業方法は何ですか?
ありがとう! あなたが追求したいのであれば、さらに関連する質問があります:http://stackoverflow.com/questions/628132/django-form-preview-how-to-work-with-cleaneddata best thx。 –
@insin 'obj.save()'によってエラーが発生した場合はどうなりますか?ほとんどの場合、単純な 'request.user'の場合ではないかもしれませんが、もっと複雑な場合はどうでしょうか。 'save(commit = False)'の後で検証とエラーレンダリングをどう扱うのですか? – orokusaki