summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatiasb <mbordese@gmail.com>2015-10-06 21:01:39 -0200
committerTim Graham <timograham@gmail.com>2015-10-21 13:35:50 -0400
commit12aeed8c949925488a36f0a3b3bf25dfc9407cbf (patch)
tree007b2fcce91bf39e308b99415b64951a902055da
parentbab9c0934243a89730ccdc9a754b3c20a455a526 (diff)
Fixed #24976 -- Fixed missing form label in tabular inline.
If the model form had a form field specified, the label rendered as "None".
-rw-r--r--django/contrib/admin/helpers.py11
-rw-r--r--tests/admin_inlines/admin.py1
-rw-r--r--tests/admin_inlines/tests.py8
3 files changed, 19 insertions, 1 deletions
diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
index 1dab27966f..2c712f6e93 100644
--- a/django/contrib/admin/helpers.py
+++ b/django/contrib/admin/helpers.py
@@ -265,7 +265,16 @@ class InlineAdminFormSet(object):
'help_text': help_text_for_field(field_name, self.opts.model),
}
else:
- yield self.formset.form.base_fields[field_name]
+ form_field = self.formset.form.base_fields[field_name]
+ label = form_field.label
+ if label is None:
+ label = label_for_field(field_name, self.opts.model, self.opts)
+ yield {
+ 'label': label,
+ 'widget': form_field.widget,
+ 'required': form_field.required,
+ 'help_text': form_field.help_text,
+ }
def _media(self):
media = self.opts.media + self.formset.media
diff --git a/tests/admin_inlines/admin.py b/tests/admin_inlines/admin.py
index 136cf3a96c..65d74a4c81 100644
--- a/tests/admin_inlines/admin.py
+++ b/tests/admin_inlines/admin.py
@@ -72,6 +72,7 @@ class InnerInline3(admin.StackedInline):
class TitleForm(forms.ModelForm):
+ title1 = forms.CharField(max_length=100)
def clean(self):
cleaned_data = self.cleaned_data
diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py
index 6cbd0f60af..ea6dcbf517 100644
--- a/tests/admin_inlines/tests.py
+++ b/tests/admin_inlines/tests.py
@@ -97,6 +97,14 @@ class TestInline(TestDataMixin, TestCase):
self.assertEqual(response.status_code, 302)
self.assertEqual(len(Fashionista.objects.filter(person__firstname='Imelda')), 1)
+ def test_custom_form_tabular_inline_label(self):
+ """
+ A model form with a form field specified (TitleForm.title1) should have
+ its label rendered in the tabular inline.
+ """
+ response = self.client.get(reverse('admin:admin_inlines_titlecollection_add'))
+ self.assertContains(response, '<th class="required">Title1</th>', html=True)
+
def test_tabular_non_field_errors(self):
"""
Ensure that non_field_errors are displayed correctly, including the