'How to POST image of nested serializer using postman django APIVIEW
I know how to post image for normal field (using form-data in postman) but I'm stack when I need to post nested serializer contain an image field.
Serializer.py looks like:
class ProgramSerializer(serializers.ModelSerializer):
image=ImageSerializer()
class Meta:
model = Program
exclude = ('create_date')
class ImageSerializer(serializers.ModelSerializer):
class Meta:
model = Image
field= ('image','name')
views.py :
class program_apiView(APIView):
def post(self, request):
parser_classes = [MultiPartParser,FormParser]
serializer = programSerializer(data= request.data)
if serializer.is_valid():
serializer.save()
return Response(
serializer.data,
status = status.HTTP_201_CREATED
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
