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

13813 fix virtual chassis member count (#13823)

* 13813 fix virtual chassis member count

* 13813 add test
This commit is contained in:
Arthur Hanson
2023-09-20 10:57:35 -07:00
committed by GitHub
parent 6fb980349f
commit 7a410dfd00
2 changed files with 11 additions and 2 deletions

View File

@@ -52,12 +52,13 @@ def post_save_receiver(sender, instance, created, **kwargs):
for field_name, counter_name in get_counters_for_model(sender):
parent_model = sender._meta.get_field(field_name).related_model
new_pk = getattr(instance, field_name, None)
old_pk = instance.tracker.get(field_name) if field_name in instance.tracker else None
has_old_field = field_name in instance.tracker
old_pk = instance.tracker.get(field_name) if has_old_field else None
# 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 and (old_pk or created):
if new_pk is not None and (has_old_field or created):
update_counter(parent_model, new_pk, counter_name, 1)