Ticket #9362: 9362_r10178.diff

File 9362_r10178.diff, 4.5 KB (added by carljm, 6 years ago)
  • django/contrib/admin/helpers.py

     
    137137        self.formset = formset
    138138        self.original = original
    139139        if original is not None:
    140             self.original.content_type_id = ContentType.objects.get_for_model(original).pk
     140            self.original_content_type_id = ContentType.objects.get_for_model(original).pk
    141141        self.show_url = original and hasattr(original, 'get_absolute_url')
    142142        super(InlineAdminForm, self).__init__(form, fieldsets, prepopulated_fields)
    143143
  • 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_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a></p>
    1414  {% endif %}
    1515  {% if inline_admin_form.form.non_field_errors %}{{ inline_admin_form.form.non_field_errors }}{% endif %}
    1616
  • django/contrib/admin/templates/admin/edit_inline/tabular.html

     
    2424        <td class="original">
    2525          {% if inline_admin_form.original or inline_admin_form.show_url %}<p>
    2626          {% if inline_admin_form.original %} {{ inline_admin_form.original }}{% endif %}
    27           {% 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 %}
     27          {% 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 %}
    2828            </p>{% endif %}
    2929          {{ inline_admin_form.pk_field.field }} {{ inline_admin_form.fk_field.field }}
    3030          {% 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