我正在使用m2m_changed
,但我仍然无法在form.save_m2m
之后观察到数据的明显更改(已添加的内容,已移除的内容)。
但如果我单独添加它们(.add,.remove)等,我可以看到更改。
那么,最好的方法是什么?我应该删除form.save_m2m
并手动更新多对多记录(.add
,.remove
),这样信号才能生效,我可以跟踪更改吗?
代码在这里:
@receiver(m2m_changed, sender=ModelName.abc.through)
def func(sender, instance, action, model, pk_set, *args, **kwargs):
print pk_set - Its printing what I have submitted recently but not showing what is added newly and what is removed newly. I tried with all different actions(pre_add, post_add etc). This function is being called for all those actions.
保存部分:
form.save()
form.save_m2m()