[Answered ]-Return Custom Response on Django Rest Framework Generics Retrieve API View

1👍

Try to use serializer class attribute as self.serializer_class(queryset, many=True), and serialize your data so:

class GetClientDetails(generics.RetrieveAPIView):
    queryset = TablePVUser.objects.all()
    serializer_class = TablePVUserSerializer
    lookup_field = 'pv_owner'

    def get(self, request, pv_owner):
        queryset = self.get_queryset().filter(pv_owner=pv_owner, user__is_active=True)
        serializer = self.serializer_class(queryset, many=True)
        data = serializer.data
        return Response({'Message': 'Users active loaded successfully', 'data': data}, status=status.HTTP_201_CREATED)

Leave a comment