@@ -37,7 +37,7 @@ def rebuild_paths(obj):
37
37
38
38
39
39
#
40
- # Site /rack/device assignment
40
+ # Location /rack/device assignment
41
41
#
42
42
43
43
@receiver (post_save , sender = Location )
@@ -47,18 +47,11 @@ def handle_location_site_change(instance, created, **kwargs):
47
47
object instead of calling update() on the QuerySet to ensure the proper change records get created for each.
48
48
"""
49
49
if not created :
50
- for location in instance .get_children ():
51
- location .site = instance .site
52
- location .save ()
53
- for rack in Rack .objects .filter (location = instance ).exclude (site = instance .site ):
54
- rack .site = instance .site
55
- rack .save ()
56
- for device in Device .objects .filter (location = instance ).exclude (site = instance .site ):
57
- device .site = instance .site
58
- device .save ()
59
- for powerpanel in PowerPanel .objects .filter (location = instance ).exclude (site = instance .site ):
60
- powerpanel .site = instance .site
61
- powerpanel .save ()
50
+ instance .get_descendants ().update (site = instance .site )
51
+ locations = instance .get_descendants (include_self = True ).values_list ('pk' , flat = True )
52
+ Rack .objects .filter (location__in = locations ).update (site = instance .site )
53
+ Device .objects .filter (location__in = locations ).update (site = instance .site )
54
+ PowerPanel .objects .filter (location__in = locations ).update (site = instance .site )
62
55
63
56
64
57
@receiver (post_save , sender = Rack )
@@ -67,10 +60,7 @@ def handle_rack_site_change(instance, created, **kwargs):
67
60
Update child Devices if Site or Location assignment has changed.
68
61
"""
69
62
if not created :
70
- for device in Device .objects .filter (rack = instance ).exclude (site = instance .site , location = instance .location ):
71
- device .site = instance .site
72
- device .location = instance .location
73
- device .save ()
63
+ Device .objects .filter (rack = instance ).update (site = instance .site , location = instance .location )
74
64
75
65
76
66
#
0 commit comments