Django FormWizard를 사용하여 기존 개체를 편집하려고합니다. this blog post에 설명 된 기술을 따르고 있지만 작동하지 않습니다. 내 편집 화면은 다음과 같습니다.Django Formwizard 편집 : 초기 데이터 얻기
@login_required
def edit_wizard(request, id):
thing = get_object_or_404(Thing, pk=id)
if thing.user != request.user:
raise HttpResponseForbidden()
else:
initial = {0: {'year': thing.year,
'make': thing.make,
'series': thing.series,
....etc.
},
1: {'condition': thing.condition,
....etc.
},
}
form = CreateWizard.as_view([StepOneForm, StepTwoForm, StepThreeForm], initial_dict=initial)
return form(context=RequestContext(request), request=request)
사용자가 개체를 편집 할 수 있도록 마법사에 초기 데이터를 제공하는 방법을 이해할 수 있습니까? 당신의 아이디어에 감사드립니다!
편집 :이 아래 @ sneawo의 대답에 의해 해결되었다
TypeError at /edit/10/ __init__() takes exactly 1 argument (3 given)
하지만 여전히 초기 데이터가 전달되지 않으며, (2/18/13)
은을 얻고 있었다 대신 마법사가 새 개체를 만듭니다.
편집 : (2/19/13)
class CreateWizard(SessionWizardView):
file_storage = FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT))
def done(self, form_list, **kwargs):
instance = Thing()
for form in form_list:
for field, value in form.cleaned_data.iteritems():
setattr(instance, field, value)
instance.user = self.request.user
instance.save()
return render_to_response('wizard-done.html', {
'form_data': [form.cleaned_data for form in form_list],
})
당신이''else' 상태 '일 = 것 (사용자 = request.user)를 사용하는 이유는 무엇입니까? – sneawo
예. 예. 내 실수. 그러나이 조건은 이제 TypeError : __init __()가 정확히 1 개의 인수 (주어진 3 개)를가집니다. 위의 세부 정보가 추가되었습니다. 어떤 아이디어 주셔서 감사합니다! –
'CreateWizard' 클래스의 코드를 보여줄 수 있습니까? – sneawo