django信号:接收器和代理模型?

时间:2021-10-15 19:21:54

I set a receiver on a post_save signal and I was hoping catching the signals for all the proxy of my Model by setting the sender to the main Model but it does not seem to work:

我在post_save信号上设置了一个接收器,我希望通过将发送器设置为主模型来捕获模型的所有代理的信号,但它似乎不起作用:

class MyObject(models.Model):
    ....

class MyObjectProxy(MyObject):

    class Meta:
        proxy = True

# The receiver
# How to avoid writing another one for sender=MyObjectProxy ?
@receiver(post_save, sender=MyObject)
...

My receiver is not triggered when that happens:

发生这种情况时,不会触发我的接收器:

obj = MyObjectProxy()
obj.save()

Is that normal? I have to set a receiver for each proxy? Can I set sender to a list of models?

这是正常的吗?我必须为每个代理设置一个接收器?我可以将发件人设置为模型列表吗?

Thanks.

1 个解决方案

#1


1  

As of now, I think that a list of models is the only working way. There is an open discussion about that specific issue.

截至目前,我认为模型列表是唯一的工作方式。有关该特定问题的公开讨论。

#1


1  

As of now, I think that a list of models is the only working way. There is an open discussion about that specific issue.

截至目前,我认为模型列表是唯一的工作方式。有关该特定问题的公开讨论。