I am overwriting to_representation method on a Serializer in order to be able to return key/val pair Object as a result instead of a default array. This is the method overwritten :
def to_representation(self, instance):
row = super(DataSerializer, self).to_representation(instance)
return {row[“d”]: row}
And although it works fiine and actually return a key/val pair Object, but the object it self comes in a array as it’s only element. How can I handle this issue ? I tried overwriting list method on the ViewSet like this :
def list(self, request, *args, **kwrags):
queryset= self.filter_queryset(self.get_queryset())
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
but returned me only first element of my data.