0
此代码位于类中。我需要访问类在自己定义的变量。我怎么能把自己传递给entry_deletion_images_delete?将自我传递给函数
@receiver(pre_delete, sender=Document, dispatch_uid='document_delete_signal')
def entry_deletion_images_delete(sender, instance, using, **kwargs):
for key, value in self.SIZES.items():
os.remove(self.base_dir + instance.image_main.name)
由于此函数使用内置参数,因此仅将自身作为新参数是不可能的。
[我怎样才能有一个Django信号调用模型方法?](http://stackoverflow.com/questions/12549977/how-can-i-have-a-django-signal-call-a -model-method) – Anentropic
有没有办法可以作为一个实例方法工作,你需要使用classmethod http://stackoverflow.com/a/12550857/202168 https://docs.python.org/2/library/ functions.html#classmethod – Anentropic
对不起,但什么是'自我'?它应该包含在你的案件中的哪个对象?它不是'实例'吗? –