📜  从模型中删除实例 od 数据时的 django 触发器 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:34.375000             🧑  作者: Mango

代码示例1
class ImageQuerySet(models.QuerySet):

    def delete(self, *args, **kwargs):
        for obj in self:
            obj.img.delete()
        super(ImageQuerySet, self).delete(*args, **kwargs)

class Image(models.Model):
    objects = ImageQuerySet.as_manager()
    img = models.ImageField(upload_to=get_image_path)
    ...
    def delete(self, *args, **kwargs):
        self.img.delete()
        super(Image, self).delete(*args, **kwargs)