66from dcim .choices import CableEndChoices , LinkStatusChoices
77from virtualization .models import VMInterface
88from .models import (
9- Cable , CablePath , CableTermination , ConsolePort , ConsoleServerPort , Device , DeviceBay , FrontPort , Interface ,
10- InventoryItem , ModuleBay , PathEndpoint , PowerOutlet , PowerPanel , PowerPort , Rack , RearPort , Location ,
9+ Cable , CablePath , CableTermination , Device , FrontPort , Interface , PathEndpoint , PowerPanel , Rack , Location ,
1110 VirtualChassis ,
1211)
1312from .models .cables import trace_paths
14- from .utils import create_cablepath , rebuild_paths
15-
16- COMPONENT_MODELS = (
17- ConsolePort ,
18- ConsoleServerPort ,
19- DeviceBay ,
20- FrontPort ,
21- Interface ,
22- InventoryItem ,
23- ModuleBay ,
24- PowerOutlet ,
25- PowerPort ,
26- RearPort ,
27- )
13+ from .utils import create_cablepath , rebuild_paths , update_device_components
2814
2915
3016#
@@ -44,6 +30,9 @@ def handle_location_site_change(instance, created, **kwargs):
4430 Device .objects .filter (location__in = locations ).update (site = instance .site )
4531 PowerPanel .objects .filter (location__in = locations ).update (site = instance .site )
4632 CableTermination .objects .filter (_location__in = locations ).update (_site = instance .site )
33+ # Update component models for devices in these locations
34+ for device in Device .objects .filter (location__in = locations ):
35+ update_device_components (device )
4736
4837
4938@receiver (post_save , sender = Rack )
@@ -53,6 +42,9 @@ def handle_rack_site_change(instance, created, **kwargs):
5342 """
5443 if not created :
5544 Device .objects .filter (rack = instance ).update (site = instance .site , location = instance .location )
45+ # Update component models for devices in this rack
46+ for device in Device .objects .filter (rack = instance ):
47+ update_device_components (device )
5648
5749
5850@receiver (post_save , sender = Device )
@@ -61,12 +53,7 @@ def handle_device_site_change(instance, created, **kwargs):
6153 Update child components to update the parent Site, Location, and Rack when a Device is saved.
6254 """
6355 if not created :
64- for model in COMPONENT_MODELS :
65- model .objects .filter (device = instance ).update (
66- _site = instance .site ,
67- _location = instance .location ,
68- _rack = instance .rack ,
69- )
56+ update_device_components (instance )
7057
7158
7259#
0 commit comments