Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14355 -- Ensure that help_text is displayed for readonly field…

…s in the admin. Thanks to jester for the report, and to alexbmeng, subsume, wamberg and Julien Phalip for ther work on the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15582 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fe3c9ad55103f8fe473bdcf77d06cb958cbaf217 1 parent 791ecb4
Russell Keith-Magee authored February 19, 2011
3  django/contrib/admin/helpers.py
... ...
@@ -1,7 +1,7 @@
1 1
 from django import forms
2 2
 from django.conf import settings
3 3
 from django.contrib.admin.util import flatten_fieldsets, lookup_field
4  
-from django.contrib.admin.util import display_for_field, label_for_field
  4
+from django.contrib.admin.util import display_for_field, label_for_field, help_text_for_field
5 5
 from django.contrib.contenttypes.models import ContentType
6 6
 from django.core.exceptions import ObjectDoesNotExist
7 7
 from django.db.models.fields.related import ManyToManyRel
@@ -144,6 +144,7 @@ def __init__(self, form, field, is_first, model_admin=None):
144 144
             'name': class_name,
145 145
             'label': label,
146 146
             'field': field,
  147
+            'help_text': help_text_for_field(class_name, form._meta.model)
147 148
         }
148 149
         self.form = form
149 150
         self.model_admin = model_admin
4  django/contrib/admin/templates/admin/includes/fieldset.html
@@ -19,8 +19,8 @@
19 19
                             {{ field.field }}
20 20
                         {% endif %}
21 21
                     {% endif %}
22  
-                    {% if field.field.field.help_text %}
23  
-                        <p class="help">{{ field.field.field.help_text|safe }}</p>
  22
+                    {% if field.field.help_text %}
  23
+                        <p class="help">{{ field.field.help_text|safe }}</p>
24 24
                     {% endif %}
25 25
                 </div>
26 26
             {% endfor %}
7  django/contrib/admin/util.py
@@ -266,6 +266,13 @@ def label_for_field(name, model, model_admin=None, return_attr=False):
266 266
     else:
267 267
         return label
268 268
 
  269
+def help_text_for_field(name, model):
  270
+    try:
  271
+        help_text = model._meta.get_field_by_name(name)[0].help_text
  272
+    except models.FieldDoesNotExist:
  273
+        help_text = ""
  274
+    return smart_unicode(help_text)
  275
+
269 276
 
270 277
 def display_for_field(value, field):
271 278
     from django.contrib.admin.templatetags.admin_list import _boolean_icon
9  tests/regressiontests/admin_views/models.py
@@ -523,9 +523,12 @@ class LinkInline(admin.TabularInline):
523 523
 
524 524
 
525 525
 class Post(models.Model):
526  
-    title = models.CharField(max_length=100)
527  
-    content = models.TextField()
528  
-    posted = models.DateField(default=datetime.date.today)
  526
+    title = models.CharField(max_length=100, help_text="Some help text for the title (with unicode ŠĐĆŽćžšđ)")
  527
+    content = models.TextField(help_text="Some help text for the content (with unicode ŠĐĆŽćžšđ)")
  528
+    posted = models.DateField(
  529
+            default=datetime.date.today,
  530
+            help_text="Some help text for the date (with unicode ŠĐĆŽćžšđ)"
  531
+    )
529 532
     public = models.NullBooleanField()
530 533
 
531 534
     def awesomeness_level(self):
4  tests/regressiontests/admin_views/tests.py
@@ -2453,6 +2453,10 @@ def test_readonly_get(self):
2453 2453
         self.assertContains(response, '<div class="form-row posted">')
2454 2454
         self.assertContains(response, '<div class="form-row value">')
2455 2455
         self.assertContains(response, '<div class="form-row ">')
  2456
+        self.assertContains(response, '<p class="help">', 3)
  2457
+        self.assertContains(response, '<p class="help">Some help text for the title (with unicode ŠĐĆŽćžšđ)</p>')
  2458
+        self.assertContains(response, '<p class="help">Some help text for the content (with unicode ŠĐĆŽćžšđ)</p>')
  2459
+        self.assertContains(response, '<p class="help">Some help text for the date (with unicode ŠĐĆŽćžšđ)</p>')
2456 2460
 
2457 2461
         p = Post.objects.create(title="I worked on readonly_fields", content="Its good stuff")
2458 2462
         response = self.client.get('/test_admin/admin/admin_views/post/%d/' % p.pk)

0 notes on commit fe3c9ad

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