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 양식 미리보기 - 저장하기 전에 양식에 사용자 추가
허용되는 작동 방식은 무엇입니까?
감사를 insin, 오른쪽! 다음과 같은 추가 질문이 있습니다. http://stackoverflow.com/questions/628132/django-form-preview-how-to-work-with-cleaneddata best thx. –
@insin'obj.save()'에 의해 에러가 발생하면 어떻게 될까요? 이것은 단순한'request.user' 케이스로 대부분의 경우는 아니지만 더 복잡한 경우는 어떨까요? 'save (commit = False)'후에 유효성 검사와 에러 렌더링을 어떻게 다루는가? – orokusaki