'Selectively hit the update signal for a model

I have a model called as nodes:

class node(models.Model):
    name = models.CharField(max_length=200)
    status = models.CharField(
       max_length=32,
       choices=[],  # some list of choices
   )
    created_on = models.DateTimeField(auto_now_add=True)
    id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True, primary_key=True)

    def __str__(self):
        return self.name

A node has a status. There can be nodes which are dependent on the status of a particular node. For example: node B,C is dependent on node A. Node D is dependent on node B.

I have a post_save signal which is triggered when the status of a particular node is changed.

What I want: When I change the status of A, the status of B and C should also change accordingly. And since node D is dependent on node B, the status of D also should change as per the node B's new status.

Problem: The post_save signal hits everytime the change of any of these nodes is changed. So for example, an update signal will be fired when status of A is changes. I would then want to change the status of B and C in this trigger. But as soon as the status of B changes, the post_Save signal will again be hit and the code would not even reach to changing the status of C. How can I make sure that the status of all the dependent nodes are changed in right sequence and manner?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source