Django 的多重继承
我正在将 Django 用于一个项目,并且我想使用几个通过子类化管理类来扩展管理的应用程序。
我怎样才能让他们都成为管理类的子类?
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
VersionAdmin 和 ModerationAdmin 似乎都使用了 Python 的“协作超级”功能。所以我尝试只使用多重继承:
如果失败,您可以看看它是否以相反的顺序工作得更好。如果这样还是不行,就需要研究具体问题,找出合作超级不行的原因。
Both VersionAdmin and ModerationAdmin appear to use the "cooperative super" feature of Python. So I'd try to just use multiple inheritance:
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.