'Image Upload from a different modal's view
So I have two models and in the update method of the first modal' viewset,(using model viewset) I'm trying to add an image to my second model but facing issues.
def update(self, request, *args, **kwargs):
data = request.data
instance = self.get_object()
serializer = self.get_serializer(instance, data=data) # partial=partial)
if serializer.is_valid(raise_exception=True):
# get image from recieved data
# profileImage = data["profileImage"]
profileImage = request.data.get("profileImage", None)
## update first modal
self.perform_update(serializer)
## add an image to second modal,
secondModel.objects.filter(user=request.user.id).update(profileImage=profileImage)
I can see the url of image getting added but there is no image in the media directory. Actually I'm updating other field also, thats working fine but having issue in this image field. While direct updating in the views of the second models there is no issue. Sending formData from the frontend.
So is there a different way dealing with file objects ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
