diff options
| author | Stephen Burrows <stephen.r.burrows@gmail.com> | 2014-05-15 20:12:32 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-05-16 06:38:24 -0400 |
| commit | d64f192df188903ea5a1ab8dfd6679e5d52aaf9b (patch) | |
| tree | 4e30d099ba136c56c638483123c7477ea64995d4 /django/forms/formsets.py | |
| parent | 4a981307359d5886d7e982aad8cfdac84d21152c (diff) | |
Fixed #22628 -- Took initial forms into account when combining FormSet.min_num and FormSet.extra.
Forwardport of 79f15ab1ef from stable/1.7.x
Diffstat (limited to 'django/forms/formsets.py')
| -rw-r--r-- | django/forms/formsets.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/django/forms/formsets.py b/django/forms/formsets.py index 2309fa00bd..07cbb41409 100644 --- a/django/forms/formsets.py +++ b/django/forms/formsets.py @@ -114,7 +114,7 @@ class BaseFormSet(object): return min(self.management_form.cleaned_data[TOTAL_FORM_COUNT], self.absolute_max) else: initial_forms = self.initial_form_count() - total_forms = initial_forms + self.extra + total_forms = max(initial_forms, self.min_num) + self.extra # Allow all existing related objects/inlines to be displayed, # but don't allow extra beyond max_num. if initial_forms > self.max_num >= 0: @@ -158,8 +158,9 @@ class BaseFormSet(object): defaults['initial'] = self.initial[i] except IndexError: pass - # Allow extra forms to be empty. - if i >= self.initial_form_count(): + # Allow extra forms to be empty, unless they're part of + # the minimum forms. + if i >= self.initial_form_count() and i >= self.min_num: defaults['empty_permitted'] = True defaults.update(kwargs) form = self.form(**defaults) @@ -422,7 +423,6 @@ def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False, # limit is simply max_num + DEFAULT_MAX_NUM (which is 2*DEFAULT_MAX_NUM # if max_num is None in the first place) absolute_max = max_num + DEFAULT_MAX_NUM - extra += min_num attrs = {'form': form, 'extra': extra, 'can_order': can_order, 'can_delete': can_delete, 'min_num': min_num, 'max_num': max_num, |
