A signal m2m_changed and bug with post_remove

后端 未结 3 1875
野性不改
野性不改 2020-12-19 09:04

I need to detect a post_remove signal, so I have written :

def handler1(sender, instance, action, reverse, model, pk_set, **kwargs):
if (action == \'post_rem         


        
3条回答
  •  离开以前
    2020-12-19 09:15

    As I understand it, it's not a bug, it's just that Django does not update m2m relations in the way you expect. It does not remove the relations to be deleted then add the new ones. Instead, it clears all of the m2m relations, then adds them again.

    There's a related question Django signal m2m_changed not triggered which links to ticket 13087.

    So you can check for the pre_clear or post_clear action with the m2m_changed signal, but since those actions do not provide pk_set, it doesn't help you find the related entries before the save, as you wanted to do in your other question.

提交回复
热议问题