Ticket #9362: 9362_r9232.diff
File 9362_r9232.diff, 4.4 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/helpers.py
126 126 self.formset = formset 127 127 self.original = original 128 128 if original is not None: 129 self.original. content_type_id = ContentType.objects.get_for_model(original).pk129 self.original.my_own_content_type_id = ContentType.objects.get_for_model(original).pk 130 130 self.show_url = original and hasattr(original, 'get_absolute_url') 131 131 super(InlineAdminForm, self).__init__(form, fieldsets, prepopulated_fields) 132 132 -
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.my_own_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a></p> 14 14 {% endif %} 15 15 16 16 {% for fieldset in inline_admin_form %} -
django/contrib/admin/templates/admin/edit_inline/tabular.html
22 22 <td class="original"> 23 23 {% if inline_admin_form.original or inline_admin_form.show_url %}<p> 24 24 {% 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 %} 26 26 </p>{% endif %} 27 27 {{ inline_admin_form.pk_field.field }} 28 28 {% 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 }