Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #9362 -- Prevented inline forms from overwriting the content_ty…

…pe_id attribute on objets being inlined. Thanks to carljm for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10667 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 80a54dd23bfda4bb297f9b13f2a54c1f10664cf5 1 parent 2c24bba
@freakboy3742 freakboy3742 authored
View
2  django/contrib/admin/helpers.py
@@ -137,7 +137,7 @@ def __init__(self, formset, form, fieldsets, prepopulated_fields, original):
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)
View
2  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 %}<span class="delete">{{ inline_admin_form.deletion_field.field }} {{ inline_admin_form.deletion_field.label_tag }}</span>{% endif %}
</h3>
{% if inline_admin_form.show_url %}
- <p><a href="../../../r/{{ inline_admin_form.original.content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a></p>
+ <p><a href="../../../r/{{ inline_admin_form.original_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a></p>
{% endif %}
{% if inline_admin_form.form.non_field_errors %}{{ inline_admin_form.form.non_field_errors }}{% endif %}
View
2  django/contrib/admin/templates/admin/edit_inline/tabular.html
@@ -24,7 +24,7 @@
<td class="original">
{% if inline_admin_form.original or inline_admin_form.show_url %}<p>
{% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}
- {% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original.content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %}
+ {% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %}
</p>{% endif %}
{% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
{{ inline_admin_form.fk_field.field }}
View
0  tests/regressiontests/admin_inlines/__init__.py
No changes.
View
51 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
+<Child: I am Joe, a child of John>
+
+"""
+}
Please sign in to comment.
Something went wrong with that request. Please try again.