﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7911	Model Inheritance still doesn't work in the admin.	atomax	Brian Rosner	"Ticket #6755 was supposed to update newforms-admin to support model inheritance (as per queryset-refactor). All of this has been merged to trunk and ticket #6755 has been closed.

Still, model inheritance does not work in the admin. There is an error thrown up as follows (seen in 1.0-alpha-SVN-8061):

{{{
Exception at /admin/news/review/33/
<class 'coolsite.news.models.Comment'> has no ForeignKey to <class 'coolsite.news.models.Review'>
Request Method: 	GET
Request URL: 	        http://localhost:80000/admin/news/review/33/
Exception Type: 	Exception
Exception Value: 	<class 'coolsite.news.models.Comment'> has no ForeignKey to <class 'coolsite.news.models.Review'>
Exception Location: 	c:\usr\django\trunk\django\forms\models.py in _get_foreign_key, line 454
}}}

In fact, Comment has a foreign key to Item and Review is a subclass of Item, so the foreign key should be inherited. This is the case, because it can be accessed in the shell. But the admin interface cannot find it.


Here is the relevant code:

{{{
model.py
========
class Item(models.Model):
    title = models.TextField(null=True, blank=True)

class Comment(models.Model):
    item = models.ForeignKey(Item, related_name='comments', null=True, blank=True)
    text = models.TextField(null=True, blank=True)

class Review(Item):
    text = models.TextField(null=True, blank=True)

class Announcement(Item):
    text = models.TextField(null=True, blank=True)


admin.py
========

class CommentInline(admin.StackedInline):
    model = Comment
    extra = 1

class ItemOptions(admin.ModelAdmin):
    model = Item
    inlines = [CommentInline]

class ReviewOptions(admin.ModelAdmin):
    model = Review
    inlines = [CommentInline]

class AnnouncementOptions(admin.ModelAdmin):
    model = Announcement
    inlines = [CommentInline]

admin.site.register(Comment)
admin.site.register(Item, ItemOptions)
admin.site.register(Review, ReviewOptions)
admin.site.register(Announcement, AnnouncementOptions)
}}}"		closed	contrib.admin	dev		duplicate	admin interface, model inheritance		Unreviewed	0	0	0	0	0	0
