Installation

Installing django-permission2

  1. Install latest stable version into your python environment using pip:

    pip install django-permission2
    
  2. Once installed add permission to your INSTALLED_APPS in settings.py:

    .. code:: python
    
        INSTALLED_APPS = (
            ...
            'permission',
        )
    
  3. Add our extra authorization/authentication backend

    AUTHENTICATION_BACKENDS = (
        'django.contrib.auth.backends.ModelBackend', # default
        'permission.backends.PermissionBackend',
    )
    
  4. Follow the instructions below to apply logical permissions to django models

Autodiscovery

Like django’s admin package, django-permission2 automatically discovers the perms.py in your application directory by running ``permission.autodiscover()``. Additionally, if the perms.py module has a PERMISSION_LOGICS variable, django-permission2 automatically run the following functions to apply the permission logics.

for model, permission_logic_instance in PERMISSION_LOGICS:
    if isinstance(model, str):
        model = get_model(*model.split(".", 1))
    add_permission_logic(model, permission_logic_instance)

Note

Autodiscover feature is automatically called. To disable, use PERMISSION_AUTODISCOVER_ENABLE setting.