2011-10-20 15 views
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 

投稿後、年齢フィールドをクリーンメソッドでチェックしたいと思います。

答えて

3
formset_class = formset_factory(BookingDetailsForm, extra=number_of_peoples) 
formset_class.form = staticmethod(curry(BookingDetailsForm, trip)) 
formset = formset_class(request.POST) 
関連する問題