Inspired from
Tools used in rendering this package:
A very small library for extending the functionality of DRF ModelViewSet.
The first of out custom viewsets is the CustomSerializerViewSet that allows you to specify different serializers for different actions of a viewset.
Install Rest Framework Custom ViewSets:
pip install rest_framework_custom_viewsets
then extend you ViewSet class from viewsets.CustomSerializerViewSet
Example:
from drf_custom_viewsets.viewsets.CustomSerializerViewSet
from myapp.serializers import DefaltSerializer, CustomSerializer1, CustomSerializer2
class MyViewSet(CustomSerializerViewSet):
serializer_class = DefaultSerializer
custom_serializer_classes = {
'create': CustomSerializer1,
'update': CustomSerializer2,
}Inspired from
Tools used in rendering this package: