Ticket #10622: inheritance-changelist.diff

File inheritance-changelist.diff, 4.4 KB (added by Alex Gaynor, 16 years ago)
  • django/contrib/admin/templatetags/admin_list.py

    diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
    index a374bf5..21401ca 100644
    a b pagination = register.inclusion_tag('admin/pagination.html')(pagination)  
    7070
    7171def result_headers(cl):
    7272    lookup_opts = cl.lookup_opts
    73    
     73
    7474    for i, field_name in enumerate(cl.list_display):
    7575        attr = None
    7676        try:
    def result_headers(cl):  
    9797                            raise AttributeError, \
    9898                                "'%s' model or '%s' objects have no attribute '%s'" % \
    9999                                    (lookup_opts.object_name, cl.model_admin.__class__, field_name)
    100                
     100
    101101                try:
    102102                    header = attr.short_description
    103103                except AttributeError:
    def items_for_result(cl, result, form):  
    237237                result_repr = conditional_escape(result_repr)
    238238            yield mark_safe(u'<td%s>%s</td>' % (row_class, result_repr))
    239239    if form:
    240         yield mark_safe(force_unicode(form[cl.model._meta.pk.attname]))
     240        yield mark_safe(force_unicode(form[cl.model._meta.pk.name]))
    241241
    242242def results(cl):
    243243    if cl.formset:
  • tests/regressiontests/admin_views/models.py

    diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
    index e5e112f..3546463 100644
    a b class Person(models.Model):  
    143143    name = models.CharField(max_length=100)
    144144    gender = models.IntegerField(choices=GENDER_CHOICES)
    145145    alive = models.BooleanField()
    146    
     146
    147147    def __unicode__(self):
    148148        return self.name
    149    
     149
    150150    class Meta:
    151151        ordering = ["id"]
    152152
    def redirect_to(request, selected):  
    236236class ExternalSubscriberAdmin(admin.ModelAdmin):
    237237    actions = [external_mail, redirect_to]
    238238
     239class Media(models.Model):
     240    name = models.CharField(max_length=60)
     241
     242class Podcast(Media):
     243    release_date = models.DateField()
     244
     245class PodcastAdmin(admin.ModelAdmin):
     246    list_display = ('name', 'release_date')
     247    list_editable = ('release_date',)
     248
     249    ordering = ('name',)
     250
    239251admin.site.register(Article, ArticleAdmin)
    240252admin.site.register(CustomArticle, CustomArticleAdmin)
    241253admin.site.register(Section, inlines=[ArticleInline])
    admin.site.register(Person, PersonAdmin)  
    246258admin.site.register(Persona, PersonaAdmin)
    247259admin.site.register(Subscriber, SubscriberAdmin)
    248260admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin)
     261admin.site.register(Podcast, PodcastAdmin)
    249262
    250263# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
    251264# That way we cover all four cases:
    admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin)  
    259272admin.site.register(Book, inlines=[ChapterInline])
    260273admin.site.register(Promo)
    261274admin.site.register(ChapterXtra1)
    262 
    263 
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index ce63567..e1517e8 100644
    a b  
    11# coding: utf-8
    22
    33import re
     4import datetime
    45
    56from django.test import TestCase
    67from django.contrib.auth.models import User, Permission
    from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME  
    1213from django.utils.html import escape
    1314
    1415# local test models
    15 from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber
     16from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber, Podcast
    1617
    1718try:
    1819    set
    class AdminViewListEditable(TestCase):  
    740741    def tearDown(self):
    741742        self.client.logout()
    742743
     744    def test_inheritance(self):
     745        Podcast.objects.create(name="TWID", release_date=datetime.date.today())
     746        response = self.client.get('/test_admin/admin/admin_views/podcast/')
     747        self.failUnlessEqual(response.status_code, 200)
     748
    743749    def test_changelist_input_html(self):
    744750        response = self.client.get('/test_admin/admin/admin_views/person/')
    745751        # 2 inputs per object(the field and the hidden id field) = 6
Back to Top