class SparePart(models.Model):
name = models.CharField(max_length=255)
description = models.TextField(blank=True, null=True)
class SparePartOrderRelation(models.Model):
sparepart = models.ForeignKey(SparePart)
order = models.ForeignKey('SparePartOrder')
class SparePartOrder(models.Model):
spareparts = models.ManyToManyField(SparePart, through=SparePartOrderRelation)
def signaltest(**kwargs):
print kwargs['action']
m2m_changed.connect(signaltest, sender=SparePartOrder.spareparts.through, weak=False, dispatch_uid='signaltest')
(为简化起见,简化模型)
为什么m2m_changed
信号不会被发送并且signaltest
被调用?当我保存SparePartOrder
时?
我尝试将sender=
替换为m2m模型(SparePartOrder.spareparts
,SparePartOrderRelation
等几乎所有(可能)引用的组合。
非常感谢帮助!
干杯