Skip to content

permissions

IsOwner

Bases: permissions.BasePermission

Custom permission to only allow owners of an object to edit it.

Source code in users/permissions.py
 4
 5
 6
 7
 8
 9
10
11
12
13
class IsOwner(permissions.BasePermission):
    """
    Custom permission to only allow owners of an object to edit it.
    """

    def has_permission(self, request, view):
        return request.user and request.user.is_authenticated

    def has_object_permission(self, request, view, obj):
        return obj.creator == request.user or request.user.is_superuser

has_object_permission(request, view, obj)

Source code in users/permissions.py
12
13
def has_object_permission(self, request, view, obj):
    return obj.creator == request.user or request.user.is_superuser

has_permission(request, view)

Source code in users/permissions.py
 9
10
def has_permission(self, request, view):
    return request.user and request.user.is_authenticated