Fixed #14355 -- Ensure that help_text is displayed for readonly fields 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
This commit is contained in:
parent
791ecb4be4
commit
fe3c9ad551
|
@ -1,7 +1,7 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.admin.util import flatten_fieldsets, lookup_field
|
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.contrib.contenttypes.models import ContentType
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.db.models.fields.related import ManyToManyRel
|
from django.db.models.fields.related import ManyToManyRel
|
||||||
|
@ -144,6 +144,7 @@ class AdminReadonlyField(object):
|
||||||
'name': class_name,
|
'name': class_name,
|
||||||
'label': label,
|
'label': label,
|
||||||
'field': field,
|
'field': field,
|
||||||
|
'help_text': help_text_for_field(class_name, form._meta.model)
|
||||||
}
|
}
|
||||||
self.form = form
|
self.form = form
|
||||||
self.model_admin = model_admin
|
self.model_admin = model_admin
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
{{ field.field }}
|
{{ field.field }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if field.field.field.help_text %}
|
{% if field.field.help_text %}
|
||||||
<p class="help">{{ field.field.field.help_text|safe }}</p>
|
<p class="help">{{ field.field.help_text|safe }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -266,6 +266,13 @@ def label_for_field(name, model, model_admin=None, return_attr=False):
|
||||||
else:
|
else:
|
||||||
return label
|
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):
|
def display_for_field(value, field):
|
||||||
from django.contrib.admin.templatetags.admin_list import _boolean_icon
|
from django.contrib.admin.templatetags.admin_list import _boolean_icon
|
||||||
|
|
|
@ -523,9 +523,12 @@ class LinkInline(admin.TabularInline):
|
||||||
|
|
||||||
|
|
||||||
class Post(models.Model):
|
class Post(models.Model):
|
||||||
title = models.CharField(max_length=100)
|
title = models.CharField(max_length=100, help_text="Some help text for the title (with unicode ŠĐĆŽćžšđ)")
|
||||||
content = models.TextField()
|
content = models.TextField(help_text="Some help text for the content (with unicode ŠĐĆŽćžšđ)")
|
||||||
posted = models.DateField(default=datetime.date.today)
|
posted = models.DateField(
|
||||||
|
default=datetime.date.today,
|
||||||
|
help_text="Some help text for the date (with unicode ŠĐĆŽćžšđ)"
|
||||||
|
)
|
||||||
public = models.NullBooleanField()
|
public = models.NullBooleanField()
|
||||||
|
|
||||||
def awesomeness_level(self):
|
def awesomeness_level(self):
|
||||||
|
|
|
@ -2453,6 +2453,10 @@ class ReadonlyTest(TestCase):
|
||||||
self.assertContains(response, '<div class="form-row posted">')
|
self.assertContains(response, '<div class="form-row posted">')
|
||||||
self.assertContains(response, '<div class="form-row value">')
|
self.assertContains(response, '<div class="form-row value">')
|
||||||
self.assertContains(response, '<div class="form-row ">')
|
self.assertContains(response, '<div class="form-row ">')
|
||||||
|
self.assertContains(response, '<p class="help">', 3)
|
||||||
|
self.assertContains(response, '<p class="help">Some help text for the title (with unicode ŠĐĆŽćžšđ)</p>')
|
||||||
|
self.assertContains(response, '<p class="help">Some help text for the content (with unicode ŠĐĆŽćžšđ)</p>')
|
||||||
|
self.assertContains(response, '<p class="help">Some help text for the date (with unicode ŠĐĆŽćžšđ)</p>')
|
||||||
|
|
||||||
p = Post.objects.create(title="I worked on readonly_fields", content="Its good stuff")
|
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)
|
response = self.client.get('/test_admin/admin/admin_views/post/%d/' % p.pk)
|
||||||
|
|
Loading…
Reference in New Issue