Ticket #9532: formsets_min_num.diff
File formsets_min_num.diff, 3.1 KB (added by , 16 years ago) |
---|
-
django/forms/formsets.py
59 59 self._total_form_count = self.extra 60 60 if self._total_form_count > self.max_num and self.max_num > 0: 61 61 self._total_form_count = self.max_num 62 if self._total_form_count < self.min_num: 63 self._total_form_count = self.min_num 62 64 initial = {TOTAL_FORM_COUNT: self._total_form_count, 63 65 INITIAL_FORM_COUNT: self._initial_form_count} 64 66 self.management_form = ManagementForm(initial=initial, auto_id=self.auto_id, prefix=self.prefix) … … 273 275 return mark_safe(u'\n'.join([unicode(self.management_form), forms])) 274 276 275 277 def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False, 276 can_delete=False, max_num=0 ):278 can_delete=False, max_num=0, min_num=0): 277 279 """Return a FormSet for the given form class.""" 278 280 attrs = {'form': form, 'extra': extra, 279 281 'can_order': can_order, 'can_delete': can_delete, 280 'max_num': max_num }282 'max_num': max_num, 'min_num': min_num} 281 283 return type(form.__name__ + 'FormSet', (formset,), attrs) 282 284 283 285 def all_valid(formsets): -
django/forms/models.py
437 437 def modelformset_factory(model, form=ModelForm, formfield_callback=lambda f: f.formfield(), 438 438 formset=BaseModelFormSet, 439 439 extra=1, can_delete=False, can_order=False, 440 max_num=0, fields=None, exclude=None):440 max_num=0, min_num=0, fields=None, exclude=None): 441 441 """ 442 442 Returns a FormSet class for the given Django model class. 443 443 """ 444 444 form = modelform_factory(model, form=form, fields=fields, exclude=exclude, 445 445 formfield_callback=formfield_callback) 446 446 FormSet = formset_factory(form, formset, extra=extra, max_num=max_num, 447 can_order=can_order, can_delete=can_delete) 447 min_num=min_num, can_order=can_order, 448 can_delete=can_delete) 448 449 FormSet.model = model 449 450 return FormSet 450 451 … … 538 539 formset=BaseInlineFormSet, fk_name=None, 539 540 fields=None, exclude=None, 540 541 extra=3, can_order=False, can_delete=True, max_num=0, 541 formfield_callback=lambda f: f.formfield()):542 min_num=0, formfield_callback=lambda f: f.formfield()): 542 543 """ 543 544 Returns an ``InlineFormSet`` for the given kwargs. 544 545 … … 566 567 'fields': fields, 567 568 'exclude': exclude, 568 569 'max_num': max_num, 570 'min_num': min_num, 569 571 } 570 572 FormSet = modelformset_factory(model, **kwargs) 571 573 FormSet.fk = fk