Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#7911 closed (duplicate)

Model Inheritance still doesn't work in the admin.

Reported by: atomax Owned by: Brian Rosner
Component: contrib.admin Version: master
Severity: Keywords: admin interface, model inheritance
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


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 ''> has no ForeignKey to <class ''>
Request Method: 	GET
Request URL: 	        http://localhost:80000/admin/news/review/33/
Exception Type: 	Exception
Exception Value: 	<class ''> has no ForeignKey to <class ''>
Exception Location: 	c:\usr\django\trunk\django\forms\ 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:
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)

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], ItemOptions), ReviewOptions), AnnouncementOptions)

Change History (4)

comment:1 Changed 10 years ago by Brian Rosner

Owner: changed from nobody to Brian Rosner
Status: newassigned

People have been filing tickets with too generic ticket titles (hey, including this one too) which makes you believe that #6755 solved all model inheritance issues in the admin. That is not the case. The revision that closed the ticket as fixed fixed the problem that was described. There can always be outstanding issues :)

I will take a look into this today.

comment:2 Changed 10 years ago by Brian Rosner

Resolution: duplicate
Status: assignedclosed

Closing in favor of #7918. It has a patch and is a bit more specific along with details.

comment:3 Changed 10 years ago by atomax

great, thanks a lot Brian!

and sorry for the unspecific title.

comment:4 Changed 7 years ago by Jacob

milestone: 1.0 beta

Milestone 1.0 beta deleted

Note: See TracTickets for help on using tickets.
Back to Top