1
我對django formset有問題。我想驗證formset中的一個字段。我跟着這些鏈接 Django Passing Custom Form Parameters to FormsetDjango formset:POST formset
並且能夠創建窗體。
但我怎樣才能將我的數據發佈到formset。
這是我的形式
class BookingDetailsForm(forms.Form):
age = forms.IntegerField()
def __init__(self, trip, *args, **kwargs):
super(BookingDetailsForm, self).__init__(*args, **kwargs)
age = self.fields["age"]
trip = trip
print "This prints when formset is created"
def clean_age(self):
// want some checking here
#raise ValidationError('Error msg')
return self.cleaned_data['age']
和我的看法是
formset = formset_factory(BookingDetailsForm, extra=number_of_peoples)
formset.form = staticmethod(curry(BookingDetailsForm, trip))
// above two line is working perfectly
然後,我怎麼能發佈我的表單集?
formset = formset_factory(BookingDetailsForm, trip, request.POST)// not working
和張貼後我想檢查清潔方法中的年齡字段。