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
?我已经尝试用对 m2m 模型(等)sender=
的(可能的)引用的几乎所有组合替换SparePartOrder.spareparts
SparePartOrderRelation
帮助表示赞赏!
干杯