How can i pass a json param in get method (drf)?

class getAlarmlogsFilterByDistincts(APIView):
    permission_classes = (IsAuthenticated,)

    def get(self, request, *args, **kwargs): 
        column_name =['column_name'] #just an idea, dont works
        distincts_list =['distincts_list'] #just an idea, dont works
        column_values = [Alarmlog.objects.filter(**{column_name: x}) for x in distincts_list ]
        serialized_response = AlarmlogSerializer(column_values)

        return Response(, status=status.HTTP_200_OK)

My view is more or less like this. I need to receive a string in column_name and a list in distincts_list (maybe in json format).

What i tried:

class AlarmlogsFilterByDistinctsSerializer(serializers.Serializer): 
    distincts_list = serializers.ListField()
    column_name = serializers.CharField()  

class getAlarmlogsFilterByDistincts(CreateAPIView):
    permission_classes = (IsAuthenticated,)
    serializer_class = AlarmlogsFilterByDistinctsSerializer

    def post(self, request, *args, **kwargs): 

        column_values = columnFilter(['column_name'],['distincts_list'])
        response_serialized = serializers.serialize('json', column_values)

        return Response(response_serialized, status=status.HTTP_200_OK)

i've tried to use post method, but my response come out as a string: "[{\"model\": \"alarms.alarmlog\", \"pk\": 26, \"fields\": {\"created_at\": \"2023-01-12T17:06:19.016Z\", \"updated_at\": \"2023-01-12T17:06:19.016Z\", \"name\": \"string43\", \"description\": \"string\", \"severity\": \"low\", \"type\": \"string\", \"period\": \"string\", \"value\": \"string\", \"reference\": \"string\", \"source\": 2147483647, \"third_party_id\": \"string\", \"device\": \"string\", \"extra_content\": {}, \"occurred_at\": \"2023-01-12T16:29:39.055Z\", \"equipment\": 7}}, {\"model\": \"alarms.alarmlog\", \"pk\": 27,...

ps. sorry my english

you could return the data in the following

import json

return Response(json.dumps(response_serialized), status=status.HTTP_200_OK)
Back to Top