문제

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)

The m2m_changed signal is never triggered, therefore the m2m_changed_labs function is never called. I want the m2m_changed_labs function to be called each time a school is added to or removed from a lab.

도움이 되었습니까?

해결책

Have you tried sender=School.labs.through?

and with your receiver method like this:

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

That's the sender used in the example from the docs.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top