1
django formsetに問題があります。私はformsetの1つのフィールドを検証したい。私はこれらのリンクをたどりました Django Passing Custom Form Parameters to FormsetDjango formset:POST formset
とフォームを作成することができます。
しかし、私はformsetに私のデータをPOSTすることができます。
これは私のフォーム
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
投稿後、年齢フィールドをクリーンメソッドでチェックしたいと思います。