diff options
| author | David Sanders <dsanders11@ucsbalum.com> | 2016-03-30 04:01:15 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-04-26 10:26:25 -0400 |
| commit | a5c8a6ce19eabd96bf3b8c7bb4fb487f53928f3b (patch) | |
| tree | 3c5d54f1664a1dcba78f3336d08ad9074dfd4c12 /django | |
| parent | e2cb1018cb1e8b95fbd15de53f8b2ba70e45d36b (diff) | |
Fixed #21332, #26538 -- Fixed inconsistent and duplicate form fields on inline formsets.
Diffstat (limited to 'django')
| -rw-r--r-- | django/forms/models.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index 4ed8b746d9..7ba98e1e26 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -889,6 +889,13 @@ class BaseInlineFormSet(BaseModelFormSet): super(BaseInlineFormSet, self).__init__(data, files, prefix=prefix, queryset=qs, **kwargs) + # Add the generated field to form._meta.fields if it's defined to make + # sure validation isn't skipped on that field. + if self.form._meta.fields and self.fk.name not in self.form._meta.fields: + if isinstance(self.form._meta.fields, tuple): + self.form._meta.fields = list(self.form._meta.fields) + self.form._meta.fields.append(self.fk.name) + def initial_form_count(self): if self.save_as_new: return 0 @@ -960,13 +967,6 @@ class BaseInlineFormSet(BaseModelFormSet): form.fields[name] = InlineForeignKeyField(self.instance, **kwargs) - # Add the generated field to form._meta.fields if it's defined to make - # sure validation isn't skipped on that field. - if form._meta.fields: - if isinstance(form._meta.fields, tuple): - form._meta.fields = list(form._meta.fields) - form._meta.fields.append(self.fk.name) - def get_unique_error_message(self, unique_check): unique_check = [field for field in unique_check if field != self.fk.name] return super(BaseInlineFormSet, self).get_unique_error_message(unique_check) |
