1๐
โ
Iโve come to a solution, which is not the desired for me but it works.
I have discovered that for any unknown reason, the file/image field is being inserted into a list if I was using my MultiPartJSONParser.
To solve it I have to extract this fields from the list in the views.py before calling super().create()
or super().update()
views.py
class CreateProfileView(CreateAPIView):
serializer_class = ProfileSerializer
parser_classes = [MultiPartJSONParser]
def create(self, request, *args, **kwargs):
for key in request.FILES:
request.data[key] = request.data[key][0]
return super().update(request, *args, **kwargs)
class RUDProfileView(RetrieveUpdateDestroyAPIView):
serializer_class = ProfileSerializer
queryset = UserProfile.objects.all()
lookup_field = 'user'
parser_classes = [MultiPartJSONParser]
def update(self, request, *args, **kwargs):
for key in request.FILES:
request.data[key] = request.data[key][0]
return super().update(request, *args, **kwargs)
๐คafinkado
Source:stackexchange.com