Fixed #13174 -- Fixed missing field label for `readonly_fields` when used in `StackedInline`, thanks to benc for the report and ptone for the investigation and initial patch.
* Corrected `InlineAdminForm.__init__` to pass along `model_admin` parameter in `super` call. * Lookup the field label in the form's model, not the `model_admin` model. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12857 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
459c71e332
commit
84de614529
|
@ -140,7 +140,7 @@ class AdminReadonlyField(object):
|
|||
if not self.is_first:
|
||||
attrs["class"] = "inline"
|
||||
name = forms.forms.pretty_name(
|
||||
label_for_field(self.field, self.model_admin.model, self.model_admin)
|
||||
label_for_field(self.field, self.form._meta.model, self.model_admin)
|
||||
)
|
||||
contents = force_unicode(escape(name)) + u":"
|
||||
return mark_safe('<label%(attrs)s>%(contents)s</label>' % {
|
||||
|
@ -232,7 +232,7 @@ class InlineAdminForm(AdminForm):
|
|||
self.original_content_type_id = ContentType.objects.get_for_model(original).pk
|
||||
self.show_url = original and hasattr(original, 'get_absolute_url')
|
||||
super(InlineAdminForm, self).__init__(form, fieldsets, prepopulated_fields,
|
||||
readonly_fields)
|
||||
readonly_fields, model_admin)
|
||||
|
||||
def __iter__(self):
|
||||
for name, options in self.fieldsets:
|
||||
|
|
|
@ -38,11 +38,13 @@ class Holder(models.Model):
|
|||
class Inner(models.Model):
|
||||
dummy = models.IntegerField()
|
||||
holder = models.ForeignKey(Holder)
|
||||
readonly = models.CharField("Inner readonly label", max_length=1)
|
||||
|
||||
|
||||
class InnerInline(admin.StackedInline):
|
||||
model = Inner
|
||||
can_delete = False
|
||||
readonly_fields = ('readonly',) # For bug #13174 tests.
|
||||
|
||||
|
||||
class Holder2(models.Model):
|
||||
|
|
|
@ -4,6 +4,7 @@ from django.test import TestCase
|
|||
from models import Holder, Inner, InnerInline
|
||||
from models import Holder2, Inner2, Holder3, Inner3
|
||||
|
||||
|
||||
class TestInline(TestCase):
|
||||
fixtures = ['admin-views-users.xml']
|
||||
|
||||
|
@ -29,6 +30,15 @@ class TestInline(TestCase):
|
|||
actual = inner_formset.can_delete
|
||||
self.assertEqual(expected, actual, 'can_delete must be equal')
|
||||
|
||||
def test_readonly_stacked_inline_label(self):
|
||||
"""Bug #13174."""
|
||||
holder = Holder.objects.create(dummy=42)
|
||||
inner = Inner.objects.create(holder=holder, dummy=42, readonly='')
|
||||
response = self.client.get('/test_admin/admin/admin_inlines/holder/%i/'
|
||||
% holder.id)
|
||||
self.assertContains(response, '<label>Inner readonly label:</label>')
|
||||
|
||||
|
||||
class TestInlineMedia(TestCase):
|
||||
fixtures = ['admin-views-users.xml']
|
||||
|
||||
|
|
Loading…
Reference in New Issue