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:37:05 -0400 |
| commit | 79f15ab1ef964c0209c4484ccf62ba458fd582b3 (patch) | |
| tree | 9ccb1a3463179b96d4ca7f77ddc090accbd9cb9c /django/forms | |
| parent | 6f0dcec44c2a1175dd558d60e526c4c5e7e39c25 (diff) | |
[1.7.x] Fixed #22628 -- Took initial forms into account when combining FormSet.min_num and FormSet.extra.
Diffstat (limited to 'django/forms')
| -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 9c4c7b5b9a..a17445dbf3 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, |
