Package: django-groups-manager
Django groups managerThis application allows to create hierarchical groups by usingdjango-mptttree structure.
It is also possible to synchronize the groups with Django'sauth.modelsGroup and User, in order to take advantage of permissions applications likedjango-guardian.DocumentationOnline documentation is available athttp://django-groups-manager.readthedocs.org/.NoteVersion1.1.0changed the default slugify function fromawesome-slugifytodjango.utils.text.slugify.
To keep usingawesome-slugifyyou need to install it separately, and thencustomize the settings:fromslugifyimportslugifyGROUPS_MANAGER={# ... other settings'SLUGIFY_FUNCTION':lambdas:slugify(s,to_lower=True),'SLUGIFY_USERNAME_FUNCTION':lambdas:slugify(s,to_lower=True,separator="_")}Requirements- Python >= 3.8
- Django >= 3.2
- django-guardian for user permissions
- jsonfield == 3.1.0For older versions of Python or Django, please look at 1.2.0 (Django <3.2, Python < 3.8>) or 0.6.2 version (Django 1.x, Python < 3.5).InstallationUse pip to installdjango-groups-manager:pipinstalldjango-groups-managerTo use per-object permissions related features,django-guardianis required as well:pipinstalldjango-guardianDjango ConfigurationAddgroups_managerinto yourINSTALLED_APPS:INSTALLED_APPS=(...# 'guardian', # add as well to use permissions related features'groups_manager',)Create models withmigrate:pythonmanage.pymigrategroups_managerNote: for users that are upgrading from <0.4.2, launch:pythonmanage.pymigrategroups_manager0001--fake
pythonmanage.pymigrategroups_managerTo enable djangoauth.modelssynchronization, add to the settings module:GROUPS_MANAGER={'AUTH_MODELS_SYNC':True,}Basic usageThe common case is to create a simple parent-son relation:fromgroups_manager.modelsimportGroup,Memberfc_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 bydjango-guardian. The Group/Member relation can be used to assing objects:fromfootball.modelsimportTeamBudgetsmall_budget=TeamBudget.objects.create(euros='1000')thohir.assign_object(staff,small_budget)thohir.has_perm('change_teambudget',small_budget)# Truepalacio.has_perm('change_teambudget',small_budget)# False# or via groupmid_budget=TeamBudget.objects.create(euros='3000')staff.assign_object(mid_budget)thohir.has_perm('change_teambudget',mid_budget)# Truepalacio.has_perm('change_teambudget',mid_budget)# FalseOwner/Group members policies can be defined viaPERMISSIONSsetting, as a dictionary ofGROUPS_MANAGER, but can also be overwritten viacustom_permissionskwarg:fromfootball.modelsimportMatchfc_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)# Falsepalacio.has_perm('play_match',friendly_match)# TrueFor more complex cases, see documentation.