Role for django User model
Project description
django-role
Пакет включает в себя:
- Модель пользователя с ролью вместо групп
- Виджет для выбора прав
Роль в отличии от групп связана с моделю пользователя связью Один ко многим
Установка
pip install django-role
poetry add django-role
Использование модели пользователя
models.py
from user_role.models import AbstractUser
class User(AbstractUser):
...
settings.py
AUTH_USER_MODEL = "app_name.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.6.tar.gz
(8.7 kB
view details)
Built Distribution
File details
Details for the file django_role-0.1.6.tar.gz
.
File metadata
- Download URL: django_role-0.1.6.tar.gz
- Upload date:
- Size: 8.7 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5916ce3f66439ddfdc05e57fb98ba3bcecada1764f3dbb641543b9094809c11 |
|
MD5 | 0884ff4819b0dbd44952f84e7ece7a29 |
|
BLAKE2b-256 | dfaa67ff54694a5154ad4dbd79ad365635054b6d1e8aafcb473ec8e3818be308 |
Provenance
File details
Details for the file django_role-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: django_role-0.1.6-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4378b380e461a058b4bf135d167e18fb1ed2ef15ef14f8a74c61d2dce4d2b8ac |
|
MD5 | 719a7e16129fe7477d8b97326a4b6b9a |
|
BLAKE2b-256 | e831f2e007e0c0eaf5d021da301cf781364b722dad28aa903b16d2ea22f7132e |