There is a similar question here but that is from 2011 and Django 1.2. Many things have changed since then. I'm using Django 1.9.
I'm wondering how should I do this correctly, without any risks of messing up the filesystem. I have an ImageField
in a model:
class CartaMagicPy(models.Model):
imagen = models.ImageField(null=True, upload_to=ubicar_magicpy)
On a first moment, the image is saved. But then, the user crops the image and I get a new image assigned to the same ImageField
.
The old image is not deleted from the filesystem. How can I delete it? The problem is that model_object.imagen.path
after being updated contains the path to the new image. And if I delete it before I update it with the new image, I risk that maybe the save could fail and then I end up with no image at all. Is there a combination of post-save signals I could use? Any advice will help.