Ticket #9362: 9362_r9232.diff

File 9362_r9232.diff, 4.4 KB (added by carljm, 7 years ago)

naive fix with regression test

  • django/contrib/admin/helpers.py

     
    126126        self.formset = formset
    127127        self.original = original
    128128        if original is not None:
    129             self.original.content_type_id = ContentType.objects.get_for_model(original).pk
     129            self.original.my_own_content_type_id = ContentType.objects.get_for_model(original).pk
    130130        self.show_url = original and hasattr(original, 'get_absolute_url')
    131131        super(InlineAdminForm, self).__init__(form, fieldsets, prepopulated_fields)
    132132
  • django/contrib/admin/templates/admin/edit_inline/stacked.html

     
    1010    {% 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 %}
    1111  </h3>
    1212  {% if inline_admin_form.show_url %}
    13   <p><a href="../../../r/{{ inline_admin_form.original.content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a></p>
     13  <p><a href="../../../r/{{ inline_admin_form.original.my_own_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a></p>
    1414  {% endif %}
    1515
    1616  {% for fieldset in inline_admin_form %}
  • django/contrib/admin/templates/admin/edit_inline/tabular.html

     
    2222        <td class="original">
    2323          {% if inline_admin_form.original or inline_admin_form.show_url %}<p>
    2424          {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}
    25           {% 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 %}
     25          {% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original.my_own_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %}
    2626            </p>{% endif %}
    2727          {{ inline_admin_form.pk_field.field }}
    2828          {% spaceless %}
  • tests/regressiontests/admin_inlines/__init__.py

     
     1#
  • tests/regressiontests/admin_inlines/models.py

     
     1"""
     2Testing of admin inline formsets.
     3
     4"""
     5from django.db import models
     6from django.contrib.contenttypes.models import ContentType
     7from django.contrib.contenttypes import generic
     8
     9class Parent(models.Model):
     10    name = models.CharField(max_length=50)
     11
     12    def __unicode__(self):
     13        return self.name
     14
     15class Teacher(models.Model):
     16    name = models.CharField(max_length=50)
     17
     18    def __unicode__(self):
     19        return self.name
     20
     21class Child(models.Model):
     22    name = models.CharField(max_length=50)
     23    teacher = models.ForeignKey(Teacher)
     24
     25    content_type = models.ForeignKey(ContentType)
     26    object_id = models.PositiveIntegerField()
     27    parent = generic.GenericForeignKey()
     28
     29    def __unicode__(self):
     30        return u'I am %s, a child of %s' % (self.name, self.parent)
     31   
     32__test__ = {'API_TESTS': """
     33
     34# Regression test for #9362
     35
     36>>> sally = Teacher.objects.create(name='Sally')
     37>>> john = Parent.objects.create(name='John')
     38>>> joe = Child.objects.create(name='Joe', teacher=sally, parent=john)
     39
     40The problem depends only on InlineAdminForm and its "original" argument, so
     41we can safely set the other arguments to None/{}.
     42
     43>>> from django.contrib.admin.helpers import InlineAdminForm
     44>>> iaf = InlineAdminForm(None, None, None, {}, joe)
     45>>> iaf.original
     46<Child: I am Joe, a child of John>
     47
     48"""
     49}
Back to Top