Ticket #9362: 9362_r10178.diff
File 9362_r10178.diff, 4.5 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/helpers.py
137 137 self.formset = formset 138 138 self.original = original 139 139 if original is not None: 140 self.original .content_type_id = ContentType.objects.get_for_model(original).pk140 self.original_content_type_id = ContentType.objects.get_for_model(original).pk 141 141 self.show_url = original and hasattr(original, 'get_absolute_url') 142 142 super(InlineAdminForm, self).__init__(form, fieldsets, prepopulated_fields) 143 143 -
django/contrib/admin/templates/admin/edit_inline/stacked.html
10 10 {% 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 %} 11 11 </h3> 12 12 {% 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> 14 14 {% endif %} 15 15 {% if inline_admin_form.form.non_field_errors %}{{ inline_admin_form.form.non_field_errors }}{% endif %} 16 16 -
django/contrib/admin/templates/admin/edit_inline/tabular.html
24 24 <td class="original"> 25 25 {% if inline_admin_form.original or inline_admin_form.show_url %}<p> 26 26 {% 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 %} 28 28 </p>{% endif %} 29 29 {{ inline_admin_form.pk_field.field }} {{ inline_admin_form.fk_field.field }} 30 30 {% spaceless %} -
tests/regressiontests/admin_inlines/__init__.py
1 # -
tests/regressiontests/admin_inlines/models.py
1 """ 2 Testing of admin inline formsets. 3 4 """ 5 from django.db import models 6 from django.contrib.contenttypes.models import ContentType 7 from django.contrib.contenttypes import generic 8 9 class Parent(models.Model): 10 name = models.CharField(max_length=50) 11 12 def __unicode__(self): 13 return self.name 14 15 class Teacher(models.Model): 16 name = models.CharField(max_length=50) 17 18 def __unicode__(self): 19 return self.name 20 21 class 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 40 The problem depends only on InlineAdminForm and its "original" argument, so 41 we 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 }