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, '