Deleting files associated with model - django
- by alexBrand
I have the following code in one of my models
class PostImage(models.Model):
post = models.ForeignKey(Post, related_name="images")
# @@@@ figure out a way to have image folders per user...
image = models.ImageField(upload_to='images')
image_infowindow = models.ImageField(upload_to='images')
image_thumb = models.ImageField(upload_to='images')
image_web = models.ImageField(upload_to='images')
description = models.CharField(max_length=100)
order = models.IntegerField(null=True)
IMAGE_SIZES = {
'image_infowindow':(70,70),
'image_thumb':(100,100),
'image_web':(640,480),
}
def delete(self, *args, **kwargs):
# delete files..
self.image.delete(save=False)
self.image_thumb.delete(save=False)
self.image_web.delete(save=False)
self.image_infowindow.delete(save=False)
super(PostImage, self).delete(*args, **kwargs)
I am trying to delete the files when the delete() method is called on PostImage. However, the files are not being removed.
As you can see, I am overriding the delete() method, and deleting each ImageField. For some reason however, the files are not being removed.