django trigger when an instance od data is deleted from model

Solutions on MaxInterview for django trigger when an instance od data is deleted from model by the best coders in the world

showing results for - "django trigger when an instance od data is deleted from model"
Teo
23 Oct 2019
1class ImageQuerySet(models.QuerySet):
2
3    def delete(self, *args, **kwargs):
4        for obj in self:
5            obj.img.delete()
6        super(ImageQuerySet, self).delete(*args, **kwargs)
7
8class Image(models.Model):
9    objects = ImageQuerySet.as_manager()
10    img = models.ImageField(upload_to=get_image_path)
11    ...
12    def delete(self, *args, **kwargs):
13        self.img.delete()
14        super(Image, self).delete(*args, **kwargs)
15
similar questions