Django Role based Access Management.
Project description
Django RAM
Role based user access management for Django.
Requirements
- Python 3.6+
- Django 4.1, 4.0, 3.2, 3.1, 3.0
Installation
pip install django-ram
Optionally install with rest framework support:
pip install django-ram[rest_framework]
Add django_ram'
to your INSTALLED_APPS
setting.
INSTALLED_APPS = [
...
'django_ram',
]
./manage.py migrate
Overview
User Model
Add the RolesMixin
to your user model.
from django_ram.models import RolesMixin
class CustomUser(AbstractUser, RolesMixin):
pass
Also remember to configure AUTH_USER_MODEL
in your settings.py
module.
Declarative Roles
some_app/roles.py
from django_ram.definition import RoleDefinition
class AdminRole(RoleDefinition):
name = "Admin"
description = "System administrator."
class AuthorRole(RoleDefinition):
name = "Author"
description = "A writer of a book, article, or document."
Roles will be created (or updated) post migration to reflect role definitions in roles.py
files.
Role names have to be globally unique.
Django Admin
Register the admin class (or subclass it to expand functionality.)
from django.contrib import admin
from django_ram.admin import UserAdmin
...
admin.site.register(YourUserModel, UserAdmin)
Rest Framework Support
from django_ram.rest_framework import HasRoleBasePermission, has_role
from some_app.roles import AuthorRole
class HasAuthorRole(HasRoleBasePermission):
role_definition = AuthorRole
class PublicationViewSet(viewsets.ModelViewset):
permission_classes = [
has_role(AuthorRole),
# Is equivelant to:
HasAuthorRole,
]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-ram-0.1.2.tar.gz
(18.1 kB
view details)
Built Distribution
File details
Details for the file django-ram-0.1.2.tar.gz
.
File metadata
- Download URL: django-ram-0.1.2.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.9.6 requests/2.28.2 setuptools/62.6.0 requests-toolbelt/0.10.1 tqdm/4.65.0 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50dd91401b5483ee24d2fcbf65112650bff38161698f2efcaeeee03c9bd791cd |
|
MD5 | 9d58afca87999cee88eee4b4fdde81e8 |
|
BLAKE2b-256 | c67a4507f28c87e80c42492774469767d71015f0c5c2825b63fef047e94bbfa0 |
File details
Details for the file django_ram-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: django_ram-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.9.6 requests/2.28.2 setuptools/62.6.0 requests-toolbelt/0.10.1 tqdm/4.65.0 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c47ab9588f7495d02a779f705f9d2e229c1917e12f2b9ace4e81e4309a559df3 |
|
MD5 | 94c220405852b644adea898bf147763e |
|
BLAKE2b-256 | 359bbd7b558de03b25cffbcf4da3eb77f94d579d5a8c9cffbea2ea7031e2d9af |