【问题标题】:Django formset : POST formsetDjango 表单集:POST 表单集
【发布时间】:2011-12-11 21:30:44
【问题描述】:

我对 django formset 有疑问。我想验证表单集中的一个字段。我关注了这些链接 Django Passing Custom Form Parameters to 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

发布后我想用干净的方法检查年龄字段。

【问题讨论】:

    标签: django django-forms django-views


    【解决方案1】:
    formset_class = formset_factory(BookingDetailsForm, extra=number_of_peoples)
    formset_class.form = staticmethod(curry(BookingDetailsForm, trip))
    formset = formset_class(request.POST)
    

    【讨论】:

      猜你喜欢
      • 2020-05-30
      • 2020-11-17
      • 1970-01-01
      • 2010-12-29
      • 2016-03-18
      • 1970-01-01
      • 2018-02-08
      • 1970-01-01
      • 2011-11-30
      相关资源
      最近更新 更多