Code

Ticket #10622: inheritance-changelist.2.diff

File inheritance-changelist.2.diff, 4.4 KB (added by Alex, 5 years ago)
Line 
1diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
2index a374bf5..21401ca 100644
3--- a/django/contrib/admin/templatetags/admin_list.py
4+++ b/django/contrib/admin/templatetags/admin_list.py
5@@ -70,7 +70,7 @@ pagination = register.inclusion_tag('admin/pagination.html')(pagination)
6 
7 def result_headers(cl):
8     lookup_opts = cl.lookup_opts
9-   
10+
11     for i, field_name in enumerate(cl.list_display):
12         attr = None
13         try:
14@@ -97,7 +97,7 @@ def result_headers(cl):
15                             raise AttributeError, \
16                                 "'%s' model or '%s' objects have no attribute '%s'" % \
17                                     (lookup_opts.object_name, cl.model_admin.__class__, field_name)
18-               
19+
20                 try:
21                     header = attr.short_description
22                 except AttributeError:
23@@ -237,7 +237,7 @@ def items_for_result(cl, result, form):
24                 result_repr = conditional_escape(result_repr)
25             yield mark_safe(u'<td%s>%s</td>' % (row_class, result_repr))
26     if form:
27-        yield mark_safe(force_unicode(form[cl.model._meta.pk.attname]))
28+        yield mark_safe(force_unicode(form[cl.model._meta.pk.name]))
29 
30 def results(cl):
31     if cl.formset:
32diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
33index e5e112f..3546463 100644
34--- a/tests/regressiontests/admin_views/models.py
35+++ b/tests/regressiontests/admin_views/models.py
36@@ -143,10 +143,10 @@ class Person(models.Model):
37     name = models.CharField(max_length=100)
38     gender = models.IntegerField(choices=GENDER_CHOICES)
39     alive = models.BooleanField()
40-   
41+
42     def __unicode__(self):
43         return self.name
44-   
45+
46     class Meta:
47         ordering = ["id"]
48 
49@@ -236,6 +236,18 @@ def redirect_to(request, selected):
50 class ExternalSubscriberAdmin(admin.ModelAdmin):
51     actions = [external_mail, redirect_to]
52 
53+class Media(models.Model):
54+    name = models.CharField(max_length=60)
55+
56+class Podcast(Media):
57+    release_date = models.DateField()
58+
59+class PodcastAdmin(admin.ModelAdmin):
60+    list_display = ('name', 'release_date')
61+    list_editable = ('release_date',)
62+
63+    ordering = ('name',)
64+
65 admin.site.register(Article, ArticleAdmin)
66 admin.site.register(CustomArticle, CustomArticleAdmin)
67 admin.site.register(Section, inlines=[ArticleInline])
68@@ -246,6 +258,7 @@ admin.site.register(Person, PersonAdmin)
69 admin.site.register(Persona, PersonaAdmin)
70 admin.site.register(Subscriber, SubscriberAdmin)
71 admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin)
72+admin.site.register(Podcast, PodcastAdmin)
73 
74 # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
75 # That way we cover all four cases:
76@@ -259,5 +272,3 @@ admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin)
77 admin.site.register(Book, inlines=[ChapterInline])
78 admin.site.register(Promo)
79 admin.site.register(ChapterXtra1)
80-
81-
82diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
83index ce63567..2fd4c07 100644
84--- a/tests/regressiontests/admin_views/tests.py
85+++ b/tests/regressiontests/admin_views/tests.py
86@@ -1,6 +1,7 @@
87 # coding: utf-8
88 
89 import re
90+import datetime
91 
92 from django.test import TestCase
93 from django.contrib.auth.models import User, Permission
94@@ -12,7 +13,7 @@ from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
95 from django.utils.html import escape
96 
97 # local test models
98-from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber
99+from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber, Podcast
100 
101 try:
102     set
103@@ -740,6 +741,12 @@ class AdminViewListEditable(TestCase):
104     def tearDown(self):
105         self.client.logout()
106 
107+    def test_inheritance(self):
108+        Podcast.objects.create(name="This Week in Django",
109+            release_date=datetime.date.today())
110+        response = self.client.get('/test_admin/admin/admin_views/podcast/')
111+        self.failUnlessEqual(response.status_code, 200)
112+
113     def test_changelist_input_html(self):
114         response = self.client.get('/test_admin/admin/admin_views/person/')
115         # 2 inputs per object(the field and the hidden id field) = 6