Ticket #11418: formset.diff
File formset.diff, 2.2 KB (added by , 15 years ago) |
---|
-
django/forms/formsets.py
92 92 Instantiates and returns the i-th form instance in a formset. 93 93 """ 94 94 defaults = {'auto_id': self.auto_id, 'prefix': self.add_prefix(i)} 95 if self. data or self.files:95 if self.is_bound: 96 96 defaults['data'] = self.data 97 97 defaults['files'] = self.files 98 98 if self.initial: -
tests/regressiontests/forms/formsets.py
5 5 FormSet allows us to use multiple instance of the same form on 1 page. For now, 6 6 the best way to create a FormSet is by using the formset_factory function. 7 7 8 >>> from django.forms import Form, CharField, IntegerField, ValidationError 8 >>> from django.forms import Form, CharField, IntegerField, ValidationError, DateField 9 9 >>> from django.forms.formsets import formset_factory, BaseFormSet 10 10 11 11 >>> class Choice(Form): … … 598 598 >>> formset.management_form.prefix 599 599 'form' 600 600 601 602 # Regression test for #11418 ################################################# 603 604 >>> class ArticleForm(Form): 605 ... title = CharField() 606 ... pub_date = DateField() 607 608 >>> ArticleFormSet = formset_factory(ArticleForm) 609 >>> formset = ArticleFormSet({}) 610 >>> formset.initial_form_count() 611 0 612 >>> formset.total_form_count() 613 1 614 >>> formset.is_bound 615 True 616 >>> formset.forms[0].is_bound 617 True 618 >>> formset.is_valid() 619 True 620 >>> formset.forms[0].is_valid() 621 True 622 >>> formset.cleaned_data 623 [{}] 624 >>> data = { 625 ... 'form-TOTAL_FORMS': u'2', 626 ... 'form-INITIAL_FORMS': u'0', 627 ... 'form-0-title': u'Test', 628 ... 'form-0-pub_date': u'16 June 1904', 629 ... 'form-1-title': u'Test', 630 ... 'form-1-pub_date': u'', # <-- this date is missing but required 631 ... } 632 >>> formset = ArticleFormSet(data) 633 >>> formset.is_valid() 634 False 635 >>> formset.errors 636 [{}, {'pub_date': [u'This field is required.']}] 637 601 638 """