1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

13599 fix cached counter for edit object (#13600)

* 13599 fix cache counter

* 13599 update test

* Merge conditionals

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
Arthur Hanson
2023-08-29 12:31:13 -07:00
committed by GitHub
parent 83536fbb23
commit 065a40dfb3
2 changed files with 7 additions and 3 deletions

View File

@@ -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.
"""
@@ -39,7 +39,7 @@ def post_save_receiver(sender, instance, **kwargs):
# Update the counters on the old and/or new parents as needed
if old_pk is not None:
update_counter(parent_model, old_pk, counter_name, -1)
if new_pk is not None:
if new_pk is not None and (old_pk or created):
update_counter(parent_model, new_pk, counter_name, 1)