[Answered ]-Uploading image/images on Django REST Framework

1👍

Refactored the create method of the serializer and it now works

def create(self, validated_data):
        request = self.context['request']
        r_data = self.context['request'].FILES
            
        post = Post.objects.create(**validated_data)
        
        if 'image' in r_data:
            post_image = PostImage.objects.create(image=r_data['image'])
            post.image.add(post_image)
        else:
            pass
        return post

Leave a comment