1
5 명이 한번에 같은 시간에 서비스를 등록하고자하는 시스템을 원한다고 가정 해 봅시다.Formset + form, 하나의 formset으로 압축
명시 적 : 5 개의 이름 필드 (추가 = 5로 전달)와 하나의 날짜 필드.
BaseFormSet 및 add_fields를 사용해 보았지만 5 개의 날짜 필드도 얻었습니다.
의 예 forms.py :
class NameForm(forms.Form):
name = forms.CharField()
class DateForm(form.Form):
date = forms.DateField()
의 예 views.py :
NameFormSet = formset_factory(NameForm, extra=5)
#The line under will not work, but illustrates what I want to do.
NameFormSet.append(DateForm)
if request.method = 'POST':
formset = NameFormSet(request.POST)
#Do validation etc..
else:
formset = NameFormSet()
return render_to_response('template.html', { 'formset' : formset })
도와주세요은 =)