Skip to content

Instantly share code, notes, and snippets.

View ruslan-korneev's full-sized avatar
🦆
Typing ...

Ruslan Korneev ruslan-korneev

🦆
Typing ...
View GitHub Profile

Serializer and Permission per action in Django REST Framework

In Django REST Framework you have a Viewsets, which can contain multiple views (actions). But to use different serializers and permissions for each action you always need to override get_serializer_class or get_permissions methods. Here I've implemented a mixins which allow you to setup your serializers and permissions per action in a dictionaries

Usage Example

class UserViewSet(SerializerPerAction, PermissionPerAction, ModelViewSet):
    queryset = User.objects.all()
    action_serializers = {