0

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

mirodil
  • 422
  • 2
  • 8
  • 21

1 Answers1

0

Everything ok with code, I was just checking it from admin panel instead of using API.

mirodil
  • 422
  • 2
  • 8
  • 21