easy-thumbnails icon indicating copy to clipboard operation
easy-thumbnails copied to clipboard

Documentation

Open petkostas opened this issue 11 years ago • 0 comments

It would be nice to mention that when calling delete on Thumbnailer if you want to delete the Image entry in the DB you have to actually force save=False on it, to be more specific: I am using a post_delete signal in django to deal with thumbnail deletion of an ImageModel:

    # These two auto-delete files from filesystem when they are unneeded:
    @receiver(models.signals.post_delete, sender=ImageModel)
    def auto_delete_file_on_delete(sender, instance, **kwargs):
        """Deletes file from filesystem
        when corresponding `ImageModel` object is deleted.
        """
        if instance.imagefile:
            thumbmanager = get_thumbnailer(instance.imagefile)
            thumbmanager.delete(save=False)

Without the save=False thumbnails are deleted but the Model Instance (ImageModel) is saved again in the DB, adding the save=False deletes the image entry as well. I know this is not easy-thumbnails issue but rather Django's own way of dealing with deletes on files, but it would be nice to have it documented there as well since the delete method is called on a Thumbnailer instance

petkostas avatar Jan 17 '14 11:01 petkostas