Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #19609: admin Inlines doesn't display help_text for readonly fi…

…elds

Refactoring: field was renamed to field_name, since flatten_fieldsets returns field name, not field.

Original patch from Marc Aymerich Gubern
  • Loading branch information...
commit 67dd54dc841a93a67eac87dc13ed047d72f920dc 1 parent f3ae67a
@viciu viciu authored
View
2  AUTHORS
@@ -590,6 +590,8 @@ answer newbie questions, and generally made Django that much better:
ye7cakf02@sneakemail.com
ymasuda@ethercube.com
Jesse Young <adunar@gmail.com>
+ Marc Aymerich Gubern
+ Wiktor Kołodziej <wiktor@pykonik.org>
Mykola Zamkovoi <nickzam@gmail.com>
zegor
Gasper Zejn <zejn@kiberpipa.org>
View
13 django/contrib/admin/helpers.py
@@ -224,19 +224,20 @@ def __iter__(self):
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
View
7 tests/regressiontests/admin_inlines/admin.py
@@ -28,6 +28,11 @@ class Media:
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 @@ class SightingInline(admin.TabularInline):
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])
View
9 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):
View
4 tests/regressiontests/admin_inlines/tests.py
@@ -122,6 +122,10 @@ def test_help_text(self):
response = self.client.get('/admin/admin_inlines/holder4/add/')
self.assertContains(response, '<p class="help">Awesome stacked help text is awesome.</p>', 4)
self.assertContains(response, '<img src="/static/admin/img/icon-unknown.gif" class="help help-tooltip" width="10" height="10" alt="(Awesome tabular help text is awesome.)" title="Awesome tabular help text is awesome." />', 1)
+ # ReadOnly fields
+ response = self.client.get('/admin/admin_inlines/capofamiglia/add/')
+ self.assertContains(response, '<img src="/static/admin/img/icon-unknown.gif" class="help help-tooltip" width="10" height="10" alt="(Help text for ReadOnlyInline)" title="Help text for ReadOnlyInline" />', 1)
+
def test_non_related_name_inline(self):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.