diff --git a/AUTHORS b/AUTHORS index c43823ce33..9089f7db90 100644 --- a/AUTHORS +++ b/AUTHORS @@ -590,6 +590,8 @@ answer newbie questions, and generally made Django that much better: ye7cakf02@sneakemail.com ymasuda@ethercube.com Jesse Young + Marc Aymerich Gubern + Wiktor KoƂodziej Mykola Zamkovoi zegor Gasper Zejn diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index 4203287123..adc2302587 100644 --- a/django/contrib/admin/helpers.py +++ b/django/contrib/admin/helpers.py @@ -224,19 +224,20 @@ class InlineAdminFormSet(object): def fields(self): fk = getattr(self.formset, "fk", None) - for i, field in enumerate(flatten_fieldsets(self.fieldsets)): - if fk and fk.name == field: + for i, field_name in enumerate(flatten_fieldsets(self.fieldsets)): + if fk and fk.name == field_name: continue - if field in self.readonly_fields: + if field_name in self.readonly_fields: yield { - 'label': label_for_field(field, self.opts.model, self.opts), + 'label': label_for_field(field_name, self.opts.model, self.opts), 'widget': { 'is_hidden': False }, - 'required': False + 'required': False, + 'help_text': help_text_for_field(field_name, self.opts.model), } else: - yield self.formset.form.base_fields[field] + yield self.formset.form.base_fields[field_name] def _media(self): media = self.opts.media + self.formset.media diff --git a/tests/regressiontests/admin_inlines/admin.py b/tests/regressiontests/admin_inlines/admin.py index 536c3ec079..44671d0ac4 100644 --- a/tests/regressiontests/admin_inlines/admin.py +++ b/tests/regressiontests/admin_inlines/admin.py @@ -28,6 +28,11 @@ class HolderAdmin(admin.ModelAdmin): js = ('my_awesome_admin_scripts.js',) +class ReadOnlyInlineInline(admin.TabularInline): + model = ReadOnlyInline + readonly_fields = ['name'] + + class InnerInline2(admin.StackedInline): model = Inner2 @@ -142,7 +147,7 @@ site.register(Novel, NovelAdmin) site.register(Fashionista, inlines=[InlineWeakness]) site.register(Holder4, Holder4Admin) site.register(Author, AuthorAdmin) -site.register(CapoFamiglia, inlines=[ConsigliereInline, SottoCapoInline]) +site.register(CapoFamiglia, inlines=[ConsigliereInline, SottoCapoInline, ReadOnlyInlineInline]) site.register(ProfileCollection, inlines=[ProfileInline]) site.register(ParentModelWithCustomPk, inlines=[ChildModel1Inline, ChildModel2Inline]) site.register(ExtraTerrestrial, inlines=[SightingInline]) diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py index 147873a9e8..31f5ecc46c 100644 --- a/tests/regressiontests/admin_inlines/models.py +++ b/tests/regressiontests/admin_inlines/models.py @@ -130,7 +130,6 @@ class Novel(models.Model): class Chapter(models.Model): novel = models.ForeignKey(Novel) - # Models for #16838 class CapoFamiglia(models.Model): @@ -138,7 +137,7 @@ class CapoFamiglia(models.Model): class Consigliere(models.Model): - name = models.CharField(max_length=100) + name = models.CharField(max_length=100, help_text='Help text for Consigliere') capo_famiglia = models.ForeignKey(CapoFamiglia, related_name='+') @@ -146,6 +145,12 @@ class SottoCapo(models.Model): name = models.CharField(max_length=100) capo_famiglia = models.ForeignKey(CapoFamiglia, related_name='+') + +class ReadOnlyInline(models.Model): + name = models.CharField(max_length=100, help_text='Help text for ReadOnlyInline') + capo_famiglia = models.ForeignKey(CapoFamiglia) + + # Models for #18433 class ParentModelWithCustomPk(models.Model): diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py index f5a54b08b6..7d00ea40de 100644 --- a/tests/regressiontests/admin_inlines/tests.py +++ b/tests/regressiontests/admin_inlines/tests.py @@ -122,6 +122,10 @@ class TestInline(TestCase): response = self.client.get('/admin/admin_inlines/holder4/add/') self.assertContains(response, '

Awesome stacked help text is awesome.

', 4) self.assertContains(response, '(Awesome tabular help text is awesome.)', 1) + # ReadOnly fields + response = self.client.get('/admin/admin_inlines/capofamiglia/add/') + self.assertContains(response, '(Help text for ReadOnlyInline)', 1) + def test_non_related_name_inline(self): """