A
A
Antigo_ptz2016-11-15 12:05:26
Django
Antigo_ptz, 2016-11-15 12:05:26

Django how to disable automatic creation of permissions?

The question is:
How can I disable automatic creation of permissions (permissions) in the auth_permission table when running the migrate command? In each model, I myself specify my rights and disable the default rights in the Meta class of the model:

class RhFactor(models.Model):
    name = models.TextField()
    code = models.TextField()

    class Meta:
        db_table = 'rh_factors'
        managed = True
        permissions = (
            ("add_rh", "Добавление резус-фактора"),
            ("change_rh", "Изменение резус-фактора"),
            ("delete_rh", "Удаление резус-фактора"),
        )
        default_permissions = ()

But, rights are automatically created for all standard tables, for example, django_content_type, django_migrations, etc. How can I disable the creation of these rights?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Podgursky, 2016-11-24
@kmmbvnr

Instead of 'django.contrib.auth' include in `INSTALLED_APPS` your own AppConfig for auth package
https://github.com/django/django/blob/master/djang...
https://docs.djangoproject.com/en/ 1.10/ref/applic...

INSTALLED_APPS = [
    ...
    'myapp.apps.AuthConfig'
    ...
]

# myapp/apps.py

from django.apps import AppConfig
from django.core import checks
from django.contrib.auth.checks import check_models_permissions, check_user_model

class AuthConfig(AppConfig):
    name = 'django.contrib.auth'
    verbose_name = _("Authentication and Authorization")

    def ready(self):
        checks.register(check_user_model, checks.Tags.models)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question