我想自动更新有关模型更改的外部应用程序。问题在于数据在事件<->用户之间存在多对多关系。我尝试使用“m2m_changed”信号。
@receiver(m2m_changed, sender=models.Event.organisers.through)
def event_changed(sender, instance, action, *args, **kwargs):
if "post" in action:
# hey api here is the new list of organisers of this
Run Code Online (Sandbox Code Playgroud)
问题在于,如果我进行一项更改,删除一个用户并添加另一个用户,那么该代码将被调用两次!这不好,我不能忽略一种类型的操作,以防仅调用该操作。我曾想过将实例推入堆栈并忽略重复项,但这看起来很混乱。有没有办法让我自己的信号只触发一次?