Skip to main content

Role for django User model

Project description

django-role

Пакет включает в себя:

  • Модель пользователя с ролью вместо групп
  • Виджет для выбора прав

Роль в отличии от групп связана с моделю пользователя связью Один ко многим

Установка

pip install django-role

poetry add django-role

Использование модели пользователя

settings.py

AUTH_USER_MODEL = "user_role.User"

Использование виджета для выбора прав

settings.py

PERMISSIONS_LABELS = {
    "add": "Добавление",
    "change": "Изменение",
    "view": "Просмотр",
    "delete": "Удаление",
}

forms.py

from django import forms
from django.contrib.auth.models import Permission
from django.utils.translation import gettext_lazy as _

from user_role.models import Role
from user_role.widgets import PermissionsSelectMultiply


class RoleCreationForm(forms.ModelForm):
    permissions = forms.ModelMultipleChoiceField(
        label=_("Permissions"),
        widget=PermissionsSelectMultiply(),
        queryset=Permission.objects.all()
    )

    class Meta:
        model = Role
        fields = [
            "name",
            "permissions"
        ]

Группирование прав и настройка виджета

class MyPermissionsSelectMultiply(PermissionsSelectMultiply):
    groups_permissions = {
        "Безопасность": ["user_role.user", "user_role.role"]
    }

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_role-0.1.5.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

django_role-0.1.5-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file django_role-0.1.5.tar.gz.

File metadata

  • Download URL: django_role-0.1.5.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.11.2 Linux/5.15.0-1034-azure

File hashes

Hashes for django_role-0.1.5.tar.gz
Algorithm Hash digest
SHA256 a1a648b6066df13235187be8b6337e2433e2ab02432529a690b05ea4832369be
MD5 91e69d34a7ec223cea831209e5c1a0fc
BLAKE2b-256 2ccbc30e9351cccbd9435f5d1982d9e63fc520d5ef3fbbf80443af4e8014d685

See more details on using hashes here.

Provenance

File details

Details for the file django_role-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: django_role-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.11.2 Linux/5.15.0-1034-azure

File hashes

Hashes for django_role-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ee23dd69584c010990577195990e6b89bc36c7510ca42f46c85c8e36217fbbd3
MD5 67990ad274a143d086fea424e2f2ff5f
BLAKE2b-256 d0832fed4fe06ee4bd22879fd8eb0b3da7efbc5da276cbb42c3515fc2249d8ca

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page