Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Wiktor Kolodziej authored February 23, 2013
2  AUTHORS
@@ -590,6 +590,8 @@ answer newbie questions, and generally made Django that much better:
590 590
     ye7cakf02@sneakemail.com
591 591
     ymasuda@ethercube.com
592 592
     Jesse Young <adunar@gmail.com>
  593
+    Marc Aymerich Gubern
  594
+    Wiktor Kołodziej <wiktor@pykonik.org>
593 595
     Mykola Zamkovoi <nickzam@gmail.com>
594 596
     zegor
595 597
     Gasper Zejn <zejn@kiberpipa.org>
13  django/contrib/admin/helpers.py
@@ -224,19 +224,20 @@ def __iter__(self):
224 224
 
225 225
     def fields(self):
226 226
         fk = getattr(self.formset, "fk", None)
227  
-        for i, field in enumerate(flatten_fieldsets(self.fieldsets)):
228  
-            if fk and fk.name == field:
  227
+        for i, field_name in enumerate(flatten_fieldsets(self.fieldsets)):
  228
+            if fk and fk.name == field_name:
229 229
                 continue
230  
-            if field in self.readonly_fields:
  230
+            if field_name in self.readonly_fields:
231 231
                 yield {
232  
-                    'label': label_for_field(field, self.opts.model, self.opts),
  232
+                    'label': label_for_field(field_name, self.opts.model, self.opts),
233 233
                     'widget': {
234 234
                         'is_hidden': False
235 235
                     },
236  
-                    'required': False
  236
+                    'required': False,
  237
+                    'help_text': help_text_for_field(field_name, self.opts.model),
237 238
                 }
238 239
             else:
239  
-                yield self.formset.form.base_fields[field]
  240
+                yield self.formset.form.base_fields[field_name]
240 241
 
241 242
     def _media(self):
242 243
         media = self.opts.media + self.formset.media
7  tests/regressiontests/admin_inlines/admin.py
@@ -28,6 +28,11 @@ class Media:
28 28
         js = ('my_awesome_admin_scripts.js',)
29 29
 
30 30
 
  31
+class ReadOnlyInlineInline(admin.TabularInline):
  32
+    model = ReadOnlyInline
  33
+    readonly_fields = ['name']
  34
+
  35
+
31 36
 class InnerInline2(admin.StackedInline):
32 37
     model = Inner2
33 38
 
@@ -142,7 +147,7 @@ class SightingInline(admin.TabularInline):
142 147
 site.register(Fashionista, inlines=[InlineWeakness])
143 148
 site.register(Holder4, Holder4Admin)
144 149
 site.register(Author, AuthorAdmin)
145  
-site.register(CapoFamiglia, inlines=[ConsigliereInline, SottoCapoInline])
  150
+site.register(CapoFamiglia, inlines=[ConsigliereInline, SottoCapoInline, ReadOnlyInlineInline])
146 151
 site.register(ProfileCollection, inlines=[ProfileInline])
147 152
 site.register(ParentModelWithCustomPk, inlines=[ChildModel1Inline, ChildModel2Inline])
148 153
 site.register(ExtraTerrestrial, inlines=[SightingInline])
9  tests/regressiontests/admin_inlines/models.py
@@ -130,7 +130,6 @@ class Novel(models.Model):
130 130
 class Chapter(models.Model):
131 131
     novel = models.ForeignKey(Novel)
132 132
 
133  
-
134 133
 # Models for #16838
135 134
 
136 135
 class CapoFamiglia(models.Model):
@@ -138,7 +137,7 @@ class CapoFamiglia(models.Model):
138 137
 
139 138
 
140 139
 class Consigliere(models.Model):
141  
-    name = models.CharField(max_length=100)
  140
+    name = models.CharField(max_length=100, help_text='Help text for Consigliere')
142 141
     capo_famiglia = models.ForeignKey(CapoFamiglia, related_name='+')
143 142
 
144 143
 
@@ -146,6 +145,12 @@ class SottoCapo(models.Model):
146 145
     name = models.CharField(max_length=100)
147 146
     capo_famiglia = models.ForeignKey(CapoFamiglia, related_name='+')
148 147
 
  148
+
  149
+class ReadOnlyInline(models.Model):
  150
+    name = models.CharField(max_length=100, help_text='Help text for ReadOnlyInline')
  151
+    capo_famiglia = models.ForeignKey(CapoFamiglia)
  152
+
  153
+
149 154
 # Models for #18433
150 155
 
151 156
 class ParentModelWithCustomPk(models.Model):
4  tests/regressiontests/admin_inlines/tests.py
@@ -122,6 +122,10 @@ def test_help_text(self):
122 122
         response = self.client.get('/admin/admin_inlines/holder4/add/')
123 123
         self.assertContains(response, '<p class="help">Awesome stacked help text is awesome.</p>', 4)
124 124
         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)
  125
+        # ReadOnly fields
  126
+        response = self.client.get('/admin/admin_inlines/capofamiglia/add/')
  127
+        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)
  128
+
125 129
 
126 130
     def test_non_related_name_inline(self):
127 131
         """

0 notes on commit 67dd54d

Please sign in to comment.
Something went wrong with that request. Please try again.