Django REST Framework - Combining and Excluding Permission Classes


Did you know?

You can combine permissions in Django REST Framework using &, |, and ~.

👇

class MyModelViewSet(viewsets.ModelViewSet):
    permission_classes = IsAuthenticated & (IsAdminUser | IsFaculty | ReadOnly)


class MyModelViewSet(viewsets.ModelViewSet):
    permission_classes = ~IsStudent & IsAuthenticated

For more, check out the Combining and Excluding Permission Classes section from Custom Permission Classes in Django REST Framework.