Python 如何使用信号预存?

Python 如何使用信号预存?,python,django,Python,Django,如何使用信号pre_save in django删除旧图像并保存新图像。 models.py中的代码是: @receiver(pre_save, sender = Treballador) def treballador_removing(sender, instance, **kwargs): this = Video.objects.get(pk=self.pk) if this.photo == self.photo: instance.photo.dele

如何使用信号pre_save in django删除旧图像并保存新图像。 models.py中的代码是:

@receiver(pre_save, sender = Treballador)
def treballador_removing(sender, instance, **kwargs):
    this = Video.objects.get(pk=self.pk)
    if this.photo == self.photo:
        instance.photo.delete(False)`

什么不好?

是什么让你认为
self
是你想要访问的对象?我想你的意思是
instance.pk
<代码>自身未定义。为什么要回到数据库?您已经有了
实例