This release is a pre-release and may not be stable for production use.
django-guardian
django-guardian is implementation of per object permissions [1] as authorization backend which is supported since Django 1.2. It won’t work with older Django releases.
Installation
To install django-guardian simply run:
pip install django-guardian
Configuration
We need to hook django-guardian into our project.
Put guardian into your INSTALLED_APPS at settings module:
INSTALLED_APPS = ( ... 'guardian', )
Add extra authorization backend:
AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', # default 'guardian.backends.ObjectPermissionBackend', )
Usage
After installation and project hooks we can finally use object permissions with Django.
Lets start really quickly:
>>> jack = User.objects.create_user('jack', 'jack@example.com', 'topsecretagentjack')
>>> admins = Group.objects.create(name='admins')
>>> jack.has_perm('change_group', admins)
False
>>> UserObjectPermission.objects.assign('change_group', user=jack, obj=admins)
<UserObjectPermission: admins | jack | change_group>
>>> jack.has_perm('change_group', admins)
True
Of course our agent jack here would not be able to change_group globally:
>>> jack.has_perm('change_group')
False
Admin integration
Replace admin.ModelAdmin with GuardedModelAdmin for those models which should have object permissions support within admin panel.
For example:
from django.contrib import admin
from myapp.models import Author
from guardian.admin import GuardedModelAdmin
# Old way:
#class AuthorAdmin(admin.ModelAdmin):
# pass
# With object permissions support
class AuthorAdmin(GuardedModelAdmin):
pass
admin.site.register(Author, AuthorAdmin)
Documentation
There is an online documentation available at http://packages.python.org/django-guardian/.
Metadata
Release files for django-guardian 1.0.0.alpha2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-guardian-1.0.0.alpha2.tar.gz | 53.8 kB | Without provenance | Details for django-guardian-1.0.0.alpha2.tar.gz |
Release files / django-guardian-1.0.0.alpha2.tar.gz
| Download URL | django-guardian-1.0.0.alpha2.tar.gz |
|---|---|
| Size | 53.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f7fbd586b2b1d5421ed5f5127d81899a69487f42488c95029469e8be339d39ac
|
|
BLAKE2b-256 checksum How to use checksums |
a7e27538744297b39560f4a91e1b6bb1c84b59e893169e9cab6d49c4aa3855ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-guardian 1.0.0.alpha2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.