Myzel394
Myzel394

Reputation: 1317

Django - Inherit Permissions in Mixins

I have two models. I want to inherit permissions from one model to another. So here's my pseud-django-code:

class BaseMixin:
    class Meta:
        abstract = True
        permissions = (
            ("can_change_something", "Can change something"),
        )


class Article(BaseMixin):
    # some fields
    class Meta:
        permissions = (
            ("can_change_something_on_articles", "Can change something on articles...")
        )

My problem: When I go to the admin panel to groups these permissions don't show up. What should I do?

Upvotes: 0

Views: 246

Answers (1)

Sina Khelil
Sina Khelil

Reputation: 1991

to inherit the Meta, change class Meta: to class Meta(BaseMixin.Meta):

Note: this only works if the model class you are inheriting from is abstract = True

instead of using permissions on your abstract model use default_permissions - make sure to add the initial default permission: 'add', 'change', 'delete', 'view'

https://docs.djangoproject.com/en/2.2/ref/models/options/#default-permissions`

Upvotes: 1

Related Questions