diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py
index b969653317..33050c3cd4 100644
--- a/django/contrib/admin/helpers.py
+++ b/django/contrib/admin/helpers.py
@@ -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('' % {
@@ -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:
diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py
index 9b491eb939..2c6a64dc7a 100644
--- a/tests/regressiontests/admin_inlines/models.py
+++ b/tests/regressiontests/admin_inlines/models.py
@@ -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):
diff --git a/tests/regressiontests/admin_inlines/tests.py b/tests/regressiontests/admin_inlines/tests.py
index 9207c5521c..1ac0100b4a 100644
--- a/tests/regressiontests/admin_inlines/tests.py
+++ b/tests/regressiontests/admin_inlines/tests.py
@@ -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, '')
+
+
class TestInlineMedia(TestCase):
fixtures = ['admin-views-users.xml']
@@ -63,4 +73,4 @@ class TestInlineMedia(TestCase):
change_url = '/test_admin/admin/admin_inlines/holder2/%i/' % holder.id
response = self.client.get(change_url)
self.assertContains(response, 'my_awesome_admin_scripts.js')
- self.assertContains(response, 'my_awesome_inline_scripts.js')
\ No newline at end of file
+ self.assertContains(response, 'my_awesome_inline_scripts.js')