因此,我阅读了 Django 源代码(1.5 后),您现在可以将多个信号注册到接收器函数:
def receiver(signal, **kwargs):
"""
A decorator for connecting receivers to signals. Used by passing in the
signal (or list of signals) and keyword arguments to connect::
@receiver(post_save, sender=MyModel)
def signal_receiver(sender, **kwargs):
...
@receiver([post_save, post_delete], sender=MyModel)
def signals_receiver(sender, **kwargs):
...
"""
... implementation code...
但是,我想将来自不同发送者的多个 post_save 信号注册到同一个函数。现在,我只是打电话
post_save.connect(fn_name, model_name)
对于我拥有的每个模型。使用新的 Django 1.5 @receiver 装饰器功能是否有更好的方法来做到这一点?