summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo <commonzenpython@gmail.com>2016-06-18 22:03:25 -0400
committerTim Graham <timograham@gmail.com>2016-06-21 14:32:19 -0400
commitc464cf88ff5eeabea0109daee35dba8a32f8644d (patch)
tree0e45c54d87fdd04be219564d83508b3bf6d7e016
parente725a68bcce4106fa3e1e8ecb0145ddef03d9005 (diff)
[1.10.x] Fixed #26729 -- Allowed overriding a form field's label/help_text in Form.__init__() for TabularInline.
Backport of 9c2d5a8d333277cc1b482a9d05f174cf4d09f24c from master
-rw-r--r--django/contrib/admin/helpers.py2
-rw-r--r--tests/admin_inlines/admin.py4
-rw-r--r--tests/admin_inlines/tests.py10
3 files changed, 15 insertions, 1 deletions
diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
index a9db82ae78..d5cf38e2ea 100644
--- a/django/contrib/admin/helpers.py
+++ b/django/contrib/admin/helpers.py
@@ -279,7 +279,7 @@ class InlineAdminFormSet(object):
'help_text': help_text_for_field(field_name, self.opts.model),
}
else:
- form_field = self.formset.form.base_fields[field_name]
+ form_field = self.formset.empty_form.fields[field_name]
label = form_field.label
if label is None:
label = label_for_field(field_name, self.opts.model, self.opts)
diff --git a/tests/admin_inlines/admin.py b/tests/admin_inlines/admin.py
index 64c89ebe99..c3bc8d7698 100644
--- a/tests/admin_inlines/admin.py
+++ b/tests/admin_inlines/admin.py
@@ -192,6 +192,10 @@ class SomeChildModelForm(forms.ModelForm):
'position': forms.HiddenInput,
}
+ def __init__(self, *args, **kwargs):
+ super(SomeChildModelForm, self).__init__(*args, **kwargs)
+ self.fields['name'].label = 'new label'
+
class SomeChildModelInline(admin.TabularInline):
model = SomeChildModel
diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py
index dc94999de4..95e38e8bb7 100644
--- a/tests/admin_inlines/tests.py
+++ b/tests/admin_inlines/tests.py
@@ -95,6 +95,16 @@ class TestInline(TestDataMixin, TestCase):
response = self.client.get(reverse('admin:admin_inlines_titlecollection_add'))
self.assertContains(response, '<th class="required">Title1</th>', html=True)
+ def test_custom_form_tabular_inline_overridden_label(self):
+ """
+ SomeChildModelForm.__init__() overrides the label of a form field.
+ That label is displayed in the TabularInline.
+ """
+ response = self.client.get(reverse('admin:admin_inlines_someparentmodel_add'))
+ field = list(response.context['inline_admin_formset'].fields())[0]
+ self.assertEqual(field['label'], 'new label')
+ self.assertContains(response, '<th class="required">New label</th>', html=True)
+
def test_tabular_non_field_errors(self):
"""
Ensure that non_field_errors are displayed correctly, including the