Skip to main content

Django groups manager

Build Status Coverage Status Version

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/.

Note

Version 1.1.0 changed the default slugify function from awesome-slugify to django.utils.text.slugify. To keep using awesome-slugify you need to install it separately, and then customize the settings:

from slugify import slugify
GROUPS_MANAGER = {
    # ... other settings
    'SLUGIFY_FUNCTION': lambda s: slugify(s, to_lower=True),
    'SLUGIFY_USERNAME_FUNCTION': lambda s: slugify(s, to_lower=True, separator="_")
}

Requirements

- Python >= 3.8
- Django >= 3.2
- django-guardian for user permissions
- jsonfield == 3.1.0

For 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).

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

  1. Add groups_manager into your INSTALLED_APPS:

    INSTALLED_APPS = (
       ...
       # 'guardian', # add as well to use permissions related features
       'groups_manager',
    )
    
  2. 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
    
  3. 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.

Release files for django-groups-manager 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-groups-manager 1.3.0
File Size Uploaded
django-groups-manager-1.3.0.tar.gz 61.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-groups-manager 1.3.0
File Interpreter ABI Platform
django_groups_manager-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 130.4 kB

Release files / django-groups-manager-1.3.0.tar.gz

Download URL django-groups-manager-1.3.0.tar.gz
Size 61.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fcc099ac8ce8efc1a620f679728d26de1f9cc8068482b9cfb06bfef1d08ad3a8
BLAKE2b-256 checksum
How to use checksums
a6473420f49d6316cb194e9ad26e3490573791f0829d24ba6a5913c3c8849818
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9

Release files / django_groups_manager-1.3.0-py3-none-any.whl

Download URL django_groups_manager-1.3.0-py3-none-any.whl
Size 68.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2588ec3e93ea89559f9f2f77563b18e40e414895b810ab80e9641e3e8bc41ff3
BLAKE2b-256 checksum
How to use checksums
fbc51ab733e6541b9e0830c50f2bdb9da51586bc2e3eb97891bf7df2fa2799e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page