mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 16:56:10 -06:00
6347 clarify name
This commit is contained in:
parent
c7a4fd14ee
commit
feaf7e33be
@ -39,14 +39,14 @@ class Counter(object):
|
|||||||
|
|
||||||
def post_save_receiver_counter(sender, instance, created, **kwargs):
|
def post_save_receiver_counter(sender, instance, created, **kwargs):
|
||||||
if created:
|
if created:
|
||||||
self.increment(instance, 1)
|
self.adjust_count(instance, 1)
|
||||||
|
|
||||||
post_save.connect(
|
post_save.connect(
|
||||||
post_save_receiver_counter, sender=self.child_model, weak=False, dispatch_uid=f'{counted_name}_post_save'
|
post_save_receiver_counter, sender=self.child_model, weak=False, dispatch_uid=f'{counted_name}_post_save'
|
||||||
)
|
)
|
||||||
|
|
||||||
def post_delete_receiver_counter(sender, instance, **kwargs):
|
def post_delete_receiver_counter(sender, instance, **kwargs):
|
||||||
self.increment(instance, -1)
|
self.adjust_count(instance, -1)
|
||||||
|
|
||||||
post_delete.connect(
|
post_delete.connect(
|
||||||
post_delete_receiver_counter,
|
post_delete_receiver_counter,
|
||||||
@ -63,7 +63,7 @@ class Counter(object):
|
|||||||
def set_counter_field(self, parent_id, value):
|
def set_counter_field(self, parent_id, value):
|
||||||
return self.parent_model.objects.filter(pk=parent_id).update(**{self.counter_name: value})
|
return self.parent_model.objects.filter(pk=parent_id).update(**{self.counter_name: value})
|
||||||
|
|
||||||
def increment(self, child, amount):
|
def adjust_count(self, child, amount):
|
||||||
parent_id = self.parent_id(child)
|
parent_id = self.parent_id(child)
|
||||||
return self.set_counter_field(parent_id, F(self.counter_name) + amount)
|
return self.set_counter_field(parent_id, F(self.counter_name) + amount)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user