suppose that I want to return in a APIView.get a (non model) object conatining 2 properties, one of them is a model object, and the other is a binary Image
I've tried several ways and had problems with serializer.
thanks!
Serializer:
class MyCustomSerializer(serializers.ModelSerializer):
class Meta:
model = MyCustom
fields = '__all__'
View:
class MyCustomGet(APIView):
def get(self, request, format=None):
serializer = MyCustomSerializer
obj = s.get_custom()
return Response({"obj": serializer(obj.obj).data, "image": obj.image})
get_custom:
class CustomClass:
obj = None
image = None
def get_custom():
r = CustomClass()
r.obj = MyCustom.objects.all().first()
r.image = PIL.Image.open('file/path.png')
return r