本文介绍了Django权限继承问题和Meta的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如果超类具有abstract = True,则可以继承Meta,否则不能继承。这是因为Django以某种方式消耗并从具体类中删除了Meta类?我想在下面的例子中做一些事情,所以Derived可以从Base获得Meta属性(在这种情况下,作为django-guardian的一部分继承权限)。
I understand Meta can be inherited if the superclass has abstract=True, but can't be inherited otherwise. Is this because Django somehow consumes and removes the Meta class from concrete classes? I'd like to do something as in the example below, so Derived can get the Meta properties from Base (in this case, to inherit permissions as part of django-guardian).
对于如何实现这一点的建议将不胜感激。
Suggestions on how to achieve this would be appreciated.
Ian
class Base(Model):
class Meta:
permissions = (("foo", "Allowed to do foo"),)
class Derived(Base):
class Meta(Base.Meta): pass
推荐答案
这篇关于Django权限继承问题和Meta的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!