[Answered ]-Custom kwarg in Django rest framework

1👍

Going by this session of the documentation, you can achieve this by adding extra action to the QuestionViewSet viewset.

From the documentation here is how this r'question_type/{pk}/question' can be achieved

from rest_framework.decorators import action

………

class QuestionViewSet(viewsets.ModelViewSet):
    """ your current code """
    
    @action(detail=True, methods=['post'])
    def question(self, request, pk=True):
        serializer = YourQuestionSerializer(data=request.data)
        if serializer.is_valid(): 
            """ your logic here """

Leave a comment