Overview
Django Guardian 2.4, released on June 1, 2022, adds Django 4.x support for object-level permissions.
Main Features
Django 4.x support
Guardian 2.4 is compatible with Django 4.0 and 4.1, integrating authentication system changes and new admin APIs.
python
from guardian.shortcuts import assign_perm, get_perms
from django.contrib.auth.models import User
user = User.objects.get(username='alice')
# article = Article.objects.get(pk=1)
# Assign object-level permission
# assign_perm('change_article', user, article)
# perms = get_perms(user, article)
# print(perms) # ['change_article']
Improved performance
Permission check queries are optimized with better caching and more efficient SQL queries.
python
from guardian.shortcuts import get_objects_for_user
from django.contrib.auth.models import User
user = User.objects.get(username='alice')
# Get objects with permission
# articles = get_objects_for_user(
# user, 'change_article', Article
# )
# print(f'{articles.count()} editable articles')
