class Lab(Model):
pass
class School(Model):
labs = ManyToManyField(Lab, related_name='schools')
def m2m_changed_labs(*args, **kwargs):
pass
m2m_changed.connect(m2m_changed_labs, sender=Lab.schools)
永远不会触发m2m_changed
信号,因此永远不会调用m2m_changed_labs
函数。我希望每次将学校添加到实验室或从实验室中删除时,都会调用m2m_changed_labs
函数。
答案 0 :(得分:0)
您是否尝试过sender=School.labs.through
?
并使用您的接收器方法:
def m2m_changed_labs(sender, **kwargs): # notice sender instead of *args
print "signal received"
这是docs中示例中使用的发件人。