简体   繁体   中英

Multiple inheritance with Django

I'm using Django for a project, and I want to use a couple of apps that extend the admin by subclassing the admin class.

How can I have them both sublass the admin class?

from django.contrib import admin
from testing.models import *
from reversion.admin import VersionAdmin
from moderation.admin import ModerationAdmin

class ItemAdmin(VersionAdmin):
    pass

admin.site.register(Item, ItemAdmin)

Both VersionAdmin and ModerationAdmin appear to use the "cooperative super" feature of Python. So I'd try to just use multiple inheritance:

class ItemAdmin(VersionAdmin, ModerationAdmin):
    pass

If this fails, you can see whether it works better with the reverse order. If this still fails, you need to study the specific issue, and find out why the cooperative super doesn't work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM