IanSR
IanSR

Reputation: 1425

Django permission inheritance problem and the Meta class

I understand the Meta class 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).

Is this possible?

class Base(Model):
    class Meta:
        permissions = (("foo", "Allowed to do foo"),)

class Derived(Base):
    class Meta(Base.Meta): pass

Upvotes: 1

Views: 2293

Answers (2)

Bernhard Vallant
Bernhard Vallant

Reputation: 50776

http://docs.djangoproject.com/en/dev/topics/db/models/#meta-inheritance

The Meta class isn't inherited straightly, Django does some funky stuff and doesn't handle all of its attributes the same way. You can have a look here if you like to know how the attributes on _meta are set.

Upvotes: 3

Adrián
Adrián

Reputation: 6255

In my case explicitly, inheriting the Meta class didn't work because of my use of the South tool. See this ticket for more info.

django-admin.py syncdb --all fixed the problem.

Upvotes: 0

Related Questions