diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index b90f5ecd79..3c1bef3f9e 100644 --- a/django/contrib/admin/helpers.py +++ b/django/contrib/admin/helpers.py @@ -1,7 +1,7 @@ from django import forms from django.conf import settings from django.contrib.admin.util import flatten_fieldsets, lookup_field -from django.contrib.admin.util import display_for_field, label_for_field +from django.contrib.admin.util import display_for_field, label_for_field, help_text_for_field from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.db.models.fields.related import ManyToManyRel @@ -144,6 +144,7 @@ class AdminReadonlyField(object): 'name': class_name, 'label': label, 'field': field, + 'help_text': help_text_for_field(class_name, form._meta.model) } self.form = form self.model_admin = model_admin diff --git a/django/contrib/admin/templates/admin/includes/fieldset.html b/django/contrib/admin/templates/admin/includes/fieldset.html index addfd0854c..6363aeeee4 100644 --- a/django/contrib/admin/templates/admin/includes/fieldset.html +++ b/django/contrib/admin/templates/admin/includes/fieldset.html @@ -19,8 +19,8 @@ {{ field.field }} {% endif %} {% endif %} - {% if field.field.field.help_text %} -
{{ field.field.field.help_text|safe }}
+ {% if field.field.help_text %} +{{ field.field.help_text|safe }}
{% endif %} {% endfor %} diff --git a/django/contrib/admin/util.py b/django/contrib/admin/util.py index 1c39614200..d3f17d67d4 100644 --- a/django/contrib/admin/util.py +++ b/django/contrib/admin/util.py @@ -266,6 +266,13 @@ def label_for_field(name, model, model_admin=None, return_attr=False): else: return label +def help_text_for_field(name, model): + try: + help_text = model._meta.get_field_by_name(name)[0].help_text + except models.FieldDoesNotExist: + help_text = "" + return smart_unicode(help_text) + def display_for_field(value, field): from django.contrib.admin.templatetags.admin_list import _boolean_icon diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py index b601267e57..58a545a64a 100644 --- a/tests/regressiontests/admin_views/models.py +++ b/tests/regressiontests/admin_views/models.py @@ -523,9 +523,12 @@ class LinkInline(admin.TabularInline): class Post(models.Model): - title = models.CharField(max_length=100) - content = models.TextField() - posted = models.DateField(default=datetime.date.today) + title = models.CharField(max_length=100, help_text="Some help text for the title (with unicode ŠĐĆŽćžšđ)") + content = models.TextField(help_text="Some help text for the content (with unicode ŠĐĆŽćžšđ)") + posted = models.DateField( + default=datetime.date.today, + help_text="Some help text for the date (with unicode ŠĐĆŽćžšđ)" + ) public = models.NullBooleanField() def awesomeness_level(self): diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 2685a05caa..f77c64bd21 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -2453,6 +2453,10 @@ class ReadonlyTest(TestCase): self.assertContains(response, '', 3) + self.assertContains(response, '
Some help text for the title (with unicode ŠĐĆŽćžšđ)
') + self.assertContains(response, 'Some help text for the content (with unicode ŠĐĆŽćžšđ)
') + self.assertContains(response, 'Some help text for the date (with unicode ŠĐĆŽćžšđ)
') p = Post.objects.create(title="I worked on readonly_fields", content="Its good stuff") response = self.client.get('/test_admin/admin/admin_views/post/%d/' % p.pk)