Issue
I wanted to delete old image from folder when uploaded new image and I tried but couldn't get result.
serializers.py
from base.services import delete_old_file
class CourseCenterSerializer(serializers.ModelSerializer):
class Meta:
model = CourseUser
fields = [
'id',
'name',
'slug',
'profile_img',
]
def update(self, instance, validated_data):
delete_old_file(instance.profile_img.path)
return super().update(instance, validated_data)
services.py
import os
def delete_old_file(path_file):
#Delete old file when upload new one
if os.path.exists(path_file):
os.remove(path_file)
What I did so far, I don't know what's wrong with it
Solution
Everything ok with code, I was just checking it from admin panel instead of using API.
Answered By - mirodil
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.