diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index 1bd55d70af..d87f717553 100644 --- a/django/contrib/admin/helpers.py +++ b/django/contrib/admin/helpers.py @@ -137,7 +137,7 @@ class InlineAdminForm(AdminForm): self.formset = formset self.original = original if original is not None: - self.original.content_type_id = ContentType.objects.get_for_model(original).pk + 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) diff --git a/django/contrib/admin/templates/admin/edit_inline/stacked.html b/django/contrib/admin/templates/admin/edit_inline/stacked.html index 10629044ed..494c351279 100644 --- a/django/contrib/admin/templates/admin/edit_inline/stacked.html +++ b/django/contrib/admin/templates/admin/edit_inline/stacked.html @@ -10,7 +10,7 @@ {% if inline_admin_formset.formset.can_delete and inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }} {{ inline_admin_form.deletion_field.label_tag }}{% endif %} {% if inline_admin_form.show_url %} -

{% trans "View on site" %}

+

{% trans "View on site" %}

{% endif %} {% if inline_admin_form.form.non_field_errors %}{{ inline_admin_form.form.non_field_errors }}{% endif %} diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html index bf947adb76..ecc14a46d3 100644 --- a/django/contrib/admin/templates/admin/edit_inline/tabular.html +++ b/django/contrib/admin/templates/admin/edit_inline/tabular.html @@ -24,7 +24,7 @@ {% if inline_admin_form.original or inline_admin_form.show_url %}

{% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %} - {% if inline_admin_form.show_url %}{% trans "View on site" %}{% endif %} + {% if inline_admin_form.show_url %}{% trans "View on site" %}{% endif %}

{% endif %} {% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %} {{ inline_admin_form.fk_field.field }} diff --git a/tests/regressiontests/admin_inlines/__init__.py b/tests/regressiontests/admin_inlines/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py new file mode 100644 index 0000000000..1893bfc508 --- /dev/null +++ b/tests/regressiontests/admin_inlines/models.py @@ -0,0 +1,51 @@ +""" +Testing of admin inline formsets. + +""" +from django.db import models +from django.contrib.contenttypes.models import ContentType +from django.contrib.contenttypes import generic + +class Parent(models.Model): + name = models.CharField(max_length=50) + + def __unicode__(self): + return self.name + +class Teacher(models.Model): + name = models.CharField(max_length=50) + + def __unicode__(self): + return self.name + +class Child(models.Model): + name = models.CharField(max_length=50) + teacher = models.ForeignKey(Teacher) + + content_type = models.ForeignKey(ContentType) + object_id = models.PositiveIntegerField() + parent = generic.GenericForeignKey() + + def __unicode__(self): + return u'I am %s, a child of %s' % (self.name, self.parent) + +__test__ = {'API_TESTS': """ + +# Regression test for #9362 + +>>> sally = Teacher.objects.create(name='Sally') +>>> john = Parent.objects.create(name='John') +>>> joe = Child.objects.create(name='Joe', teacher=sally, parent=john) + +The problem depends only on InlineAdminForm and its "original" argument, so +we can safely set the other arguments to None/{}. We just need to check that +the content_type argument of Child isn't altered by the internals of the +inline form. + +>>> from django.contrib.admin.helpers import InlineAdminForm +>>> iaf = InlineAdminForm(None, None, {}, {}, joe) +>>> iaf.original + + +""" +} \ No newline at end of file