class MySerializer(serializers.Serializer):
    id = serializers.ReadOnlyField()
field1 = serializers.ReadOnlyField()
field2 = serializers.ReadOnlyField()

def to_representation(self, data):
    pass
Return list of objects as dictionary with keys as the objects id with django rest framerwork