Fixed #24976 -- Fixed missing form label in tabular inline.
If the model form had a form field specified, the label rendered as "None".
This commit is contained in:
parent
bab9c09342
commit
12aeed8c94
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue