信号m2m_changed从未触发过

时间:2013-05-15 12:41:46

标签: python django signals django-signals m2m

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函数。

1 个答案:

答案 0 :(得分:0)

您是否尝试过sender=School.labs.through

并使用您的接收器方法:

def m2m_changed_labs(sender, **kwargs):  # notice sender instead of *args
    print "signal received"

这是docs中示例中使用的发件人。