Django groups manager through django-mptt.
Project description
Django groups manager
This application allows to create hierarchical groups by using django-mptt tree structure.
It is also possible to synchronize the groups with Django's auth.models
Group and User, in order to take advantage of permissions applications like django-guardian.
Documentation
Online documentation is available at http://django-groups-manager.readthedocs.org/.
Requirements
- Python >= 3.5
- Django >= 2
- django-guardian for user permissions
- jsonfield == 3.1.0
For older versions of Python or Django, please look at 0.6.2 version.
Installation
Use pip to install django-groups-manager
:
pip install django-groups-manager
To use per-object permissions related features, django-guardian
is required as well:
pip install django-guardian
Django Configuration
-
Add
groups_manager
into yourINSTALLED_APPS
:INSTALLED_APPS = ( ... # 'guardian', # add as well to use permissions related features 'groups_manager', )
-
Create models with
migrate
:python manage.py migrate groups_manager
Note: for users that are upgrading from <0.4.2, launch:
python manage.py migrate groups_manager 0001 --fake python manage.py migrate groups_manager
-
To enable django
auth.models
synchronization, add to the settings module:GROUPS_MANAGER = { 'AUTH_MODELS_SYNC': True, }
Basic usage
The common case is to create a simple parent-son relation:
from groups_manager.models import Group, Member
fc_internazionale = Group.objects.create(name='F.C. Internazionale Milan')
staff = Group.objects.create(name='Staff', parent=fc_internazionale)
players = Group.objects.create(name='Players', parent=fc_internazionale)
thohir = Member.objects.create(first_name='Eric', last_name='Thohir')
staff.add_member(thohir)
palacio = Member.objects.create(first_name='Rodrigo', last_name='Palacio')
players.add_member(palacio)
Per-object permissions handling is done by django-guardian
. The Group/Member relation can be used to assing objects:
from football.models import TeamBudget
small_budget = TeamBudget.objects.create(euros='1000')
thohir.assign_object(staff, small_budget)
thohir.has_perm('change_teambudget', small_budget) # True
palacio.has_perm('change_teambudget', small_budget) # False
# or via group
mid_budget = TeamBudget.objects.create(euros='3000')
staff.assign_object(mid_budget)
thohir.has_perm('change_teambudget', mid_budget) # True
palacio.has_perm('change_teambudget', mid_budget) # False
Owner/Group members policies can be defined via PERMISSIONS
setting, as a dictionary of GROUPS_MANAGER
, but can also be overwritten via custom_permissions
kwarg
:
from football.models import Match
fc_barcelona = Group.objects.create(name='FC Barcelona')
friendly_match = Match.objects.create(home=fc_internazionale, away=fc_barcelona)
palacio.assign_match(players, friendly_match, custom_permissions={'group': ['play']})
thohir.has_perm('play_match', friendly_match) # False
palacio.has_perm('play_match', friendly_match) # True
For more complex cases, see documentation.
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
Built Distribution
Hashes for django-groups-manager-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6fd3a68115f2141feab30fa2682a7ec26b968837b26732ce4ee5569ae692bba |
|
MD5 | ddbb544a893c168f86eac36ace8d7b76 |
|
BLAKE2b-256 | 3e044692dbe2d4333f380e8aa07cfd50ecc6a58ca33b5fe28cdf434a062600af |
Hashes for django_groups_manager-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1314eec3bb740ad80fa59816351d83e0681c9bce4e16d3a80600d9f60418a62e |
|
MD5 | 28795c5df713cc2f01813e6199a49a4c |
|
BLAKE2b-256 | 232928953cdf7c6330d98e64342f1c4df6691d31a531e2293499d972a9dc9e52 |