from rest_framework.negotiation import BaseContentNegotiation


class CustomClientContentNegotiation(BaseContentNegotiation):
    def select_parser(self, request, parsers):
        """
        Select the first parser in the `.parser_classes` list.
        """
        return parsers[0]

    def select_renderer(self, request, renderers, format_suffix):
        """
        Select the third renderer in the `.renderer_classes` list for the browsable API,
        otherwise use the first renderer which has media_type "application/vnd.api+json"
        """
        if 'text/html' in request.META.get('HTTP_ACCEPT', 'None'):
            return (renderers[2], renderers[2].media_type)
        return (renderers[0], renderers[0].media_type)

from rest_framework.negotiation import BaseContentNegotiation


class CustomClientContentNegotiation(BaseContentNegotiation):
    def select_parser(self, request, parsers):
        """
        Select the first parser in the `.parser_classes` list.
        """
        content_type = request.QUERY_PARAMS.get('content_type', request.content_type)
        for parser in parsers:
            if parser.media_type == content_type:
                return parser
        return parsers[0]

    def select_renderer(self, request, renderers, format_suffix):
        """
        Select the third renderer in the `.renderer_classes` list for the browsable API,
        otherwise use the first renderer which has media_type "application/vnd.api+json"
        """
        if 'text/html' in request.META.get('HTTP_ACCEPT', 'None'):
            return (renderers[2], renderers[2].media_type)
        return (renderers[0], renderers[0].media_type)

Change select_parser to choose parser based on content_type instead of manadating a parser
Change select_parser to choose parser based on content_type instead of manadating a parser

  from rest_framework.negotiation import BaseContentNegotiation
  
  
  class CustomClientContentNegotiation(BaseContentNegotiation):
      def select_parser(self, request, parsers):
          """
          Select the first parser in the `.parser_classes` list.
          """
+         content_type = request.QUERY_PARAMS.get('content_type', request.content_type)
+         for parser in parsers:
+             if parser.media_type == content_type:
+                 return parser
          return parsers[0]
  
      def select_renderer(self, request, renderers, format_suffix):
          """
          Select the third renderer in the `.renderer_classes` list for the browsable API,
          otherwise use the first renderer which has media_type "application/vnd.api+json"
          """
          if 'text/html' in request.META.get('HTTP_ACCEPT', 'None'):
              return (renderers[2], renderers[2].media_type)
          return (renderers[0], renderers[0].media_type)
  
Change select_parser to choose parser based on content_type instead of manadating a parser
## Code Before:
from rest_framework.negotiation import BaseContentNegotiation


class CustomClientContentNegotiation(BaseContentNegotiation):
    def select_parser(self, request, parsers):
        """
        Select the first parser in the `.parser_classes` list.
        """
        return parsers[0]

    def select_renderer(self, request, renderers, format_suffix):
        """
        Select the third renderer in the `.renderer_classes` list for the browsable API,
        otherwise use the first renderer which has media_type "application/vnd.api+json"
        """
        if 'text/html' in request.META.get('HTTP_ACCEPT', 'None'):
            return (renderers[2], renderers[2].media_type)
        return (renderers[0], renderers[0].media_type)

## Instruction:
Change select_parser to choose parser based on content_type instead of manadating a parser
## Code After:
from rest_framework.negotiation import BaseContentNegotiation


class CustomClientContentNegotiation(BaseContentNegotiation):
    def select_parser(self, request, parsers):
        """
        Select the first parser in the `.parser_classes` list.
        """
        content_type = request.QUERY_PARAMS.get('content_type', request.content_type)
        for parser in parsers:
            if parser.media_type == content_type:
                return parser
        return parsers[0]

    def select_renderer(self, request, renderers, format_suffix):
        """
        Select the third renderer in the `.renderer_classes` list for the browsable API,
        otherwise use the first renderer which has media_type "application/vnd.api+json"
        """
        if 'text/html' in request.META.get('HTTP_ACCEPT', 'None'):
            return (renderers[2], renderers[2].media_type)
        return (renderers[0], renderers[0].media_type)
