[Answered ]-Can I use a ModelViewSet for POST and GET of a parent of self in a model in Django REST?

1👍

You can customise your ModelViewSet to use two serializers instead of one. For example

class CategoryViewset(viewsets.ModelViewSet):
    queryset = Category.objects.all()
    serializer_class = CategorySerializer
    pagination_class = None
    
    def create(self, request):
        new_category = CategoryCreateSerializer(data=request.data)
        if new_category.is_valid:
            return Response(CategoryRetrieveSerializer(new_category).data)

Leave a comment