Fixed #10622 -- Resolved an issue with model inheritence and list_editable. Thanks oyvind and Alex Gaynor.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10178 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Brian Rosner 2009-03-29 18:52:38 +00:00
parent f0b7cc4a23
commit 69977d2045
3 changed files with 26 additions and 8 deletions

View File

@ -70,7 +70,7 @@ pagination = register.inclusion_tag('admin/pagination.html')(pagination)
def result_headers(cl): def result_headers(cl):
lookup_opts = cl.lookup_opts lookup_opts = cl.lookup_opts
for i, field_name in enumerate(cl.list_display): for i, field_name in enumerate(cl.list_display):
attr = None attr = None
try: try:
@ -97,7 +97,7 @@ def result_headers(cl):
raise AttributeError, \ raise AttributeError, \
"'%s' model or '%s' objects have no attribute '%s'" % \ "'%s' model or '%s' objects have no attribute '%s'" % \
(lookup_opts.object_name, cl.model_admin.__class__, field_name) (lookup_opts.object_name, cl.model_admin.__class__, field_name)
try: try:
header = attr.short_description header = attr.short_description
except AttributeError: except AttributeError:
@ -237,7 +237,7 @@ def items_for_result(cl, result, form):
result_repr = conditional_escape(result_repr) result_repr = conditional_escape(result_repr)
yield mark_safe(u'<td%s>%s</td>' % (row_class, result_repr)) yield mark_safe(u'<td%s>%s</td>' % (row_class, result_repr))
if form: if form:
yield mark_safe(force_unicode(form[cl.model._meta.pk.attname])) yield mark_safe(force_unicode(form[cl.model._meta.pk.name]))
def results(cl): def results(cl):
if cl.formset: if cl.formset:

View File

@ -143,10 +143,10 @@ class Person(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
gender = models.IntegerField(choices=GENDER_CHOICES) gender = models.IntegerField(choices=GENDER_CHOICES)
alive = models.BooleanField() alive = models.BooleanField()
def __unicode__(self): def __unicode__(self):
return self.name return self.name
class Meta: class Meta:
ordering = ["id"] ordering = ["id"]
@ -236,6 +236,18 @@ def redirect_to(request, selected):
class ExternalSubscriberAdmin(admin.ModelAdmin): class ExternalSubscriberAdmin(admin.ModelAdmin):
actions = [external_mail, redirect_to] actions = [external_mail, redirect_to]
class Media(models.Model):
name = models.CharField(max_length=60)
class Podcast(Media):
release_date = models.DateField()
class PodcastAdmin(admin.ModelAdmin):
list_display = ('name', 'release_date')
list_editable = ('release_date',)
ordering = ('name',)
admin.site.register(Article, ArticleAdmin) admin.site.register(Article, ArticleAdmin)
admin.site.register(CustomArticle, CustomArticleAdmin) admin.site.register(CustomArticle, CustomArticleAdmin)
admin.site.register(Section, inlines=[ArticleInline]) admin.site.register(Section, inlines=[ArticleInline])
@ -246,6 +258,7 @@ admin.site.register(Person, PersonAdmin)
admin.site.register(Persona, PersonaAdmin) admin.site.register(Persona, PersonaAdmin)
admin.site.register(Subscriber, SubscriberAdmin) admin.site.register(Subscriber, SubscriberAdmin)
admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin) admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin)
admin.site.register(Podcast, PodcastAdmin)
# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
# That way we cover all four cases: # That way we cover all four cases:
@ -259,5 +272,3 @@ admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin)
admin.site.register(Book, inlines=[ChapterInline]) admin.site.register(Book, inlines=[ChapterInline])
admin.site.register(Promo) admin.site.register(Promo)
admin.site.register(ChapterXtra1) admin.site.register(ChapterXtra1)

View File

@ -1,6 +1,7 @@
# coding: utf-8 # coding: utf-8
import re import re
import datetime
from django.test import TestCase from django.test import TestCase
from django.contrib.auth.models import User, Permission from django.contrib.auth.models import User, Permission
@ -12,7 +13,7 @@ from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.utils.html import escape from django.utils.html import escape
# local test models # local test models
from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber from models import Article, CustomArticle, Section, ModelWithStringPrimaryKey, Person, Persona, FooAccount, BarAccount, Subscriber, ExternalSubscriber, Podcast
try: try:
set set
@ -740,6 +741,12 @@ class AdminViewListEditable(TestCase):
def tearDown(self): def tearDown(self):
self.client.logout() self.client.logout()
def test_inheritance(self):
Podcast.objects.create(name="This Week in Django",
release_date=datetime.date.today())
response = self.client.get('/test_admin/admin/admin_views/podcast/')
self.failUnlessEqual(response.status_code, 200)
def test_changelist_input_html(self): def test_changelist_input_html(self):
response = self.client.get('/test_admin/admin/admin_views/person/') response = self.client.get('/test_admin/admin/admin_views/person/')
# 2 inputs per object(the field and the hidden id field) = 6 # 2 inputs per object(the field and the hidden id field) = 6