[Django]-Delete image in Django

3πŸ‘

βœ…

This is the answer that works in my case. πŸ™‚

def delete(self, *args, **kwargs):
    # You have to prepare what you need before delete the model
    storage, path = self.image.storage, self.image.path
    # Delete the model before the file
    super(Profile, self).delete(*args, **kwargs)
    # Delete the file after the model
    storage.delete(path)

It has to be added in Profile class in model.py.

Hope, it will be helpfull! πŸ™‚

πŸ‘€Johny

Leave a comment