diff --git a/netbox/utilities/counters.py b/netbox/utilities/counters.py index ee6865ca2..6b5adffad 100644 --- a/netbox/utilities/counters.py +++ b/netbox/utilities/counters.py @@ -27,7 +27,7 @@ def update_counter(model, pk, counter_name, value): # Signal handlers # -def post_save_receiver(sender, instance, **kwargs): +def post_save_receiver(sender, instance, created, **kwargs): """ Update counter fields on related objects when a TrackingModelMixin subclass is created or modified. """ @@ -40,7 +40,8 @@ def post_save_receiver(sender, instance, **kwargs): if old_pk is not None: update_counter(parent_model, old_pk, counter_name, -1) if new_pk is not None: - update_counter(parent_model, new_pk, counter_name, 1) + if old_pk or created: + update_counter(parent_model, new_pk, counter_name, 1) def post_delete_receiver(sender, instance, **kwargs):