mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-09 05:12:18 -06:00
cleanup
This commit is contained in:
@@ -957,8 +957,7 @@ class Device(
|
|||||||
if cf_defaults := CustomField.objects.get_defaults_for_model(model):
|
if cf_defaults := CustomField.objects.get_defaults_for_model(model):
|
||||||
for component in components:
|
for component in components:
|
||||||
component.custom_field_data = cf_defaults
|
component.custom_field_data = cf_defaults
|
||||||
# Set denormalized references (_site, _location, _rack) before bulk_create
|
# Set denormalized references
|
||||||
# since bulk_create bypasses the save() method
|
|
||||||
for component in components:
|
for component in components:
|
||||||
component._site = self.site
|
component._site = self.site
|
||||||
component._location = self.location
|
component._location = self.location
|
||||||
|
|||||||
@@ -315,8 +315,7 @@ class Module(PrimaryModel, ConfigContextModel):
|
|||||||
for component in create_instances:
|
for component in create_instances:
|
||||||
component.custom_field_data = cf_defaults
|
component.custom_field_data = cf_defaults
|
||||||
|
|
||||||
# Set denormalized references (_site, _location, _rack) before bulk_create
|
# Set denormalized references
|
||||||
# since bulk_create bypasses the save() method
|
|
||||||
for component in create_instances:
|
for component in create_instances:
|
||||||
component._site = self.device.site
|
component._site = self.device.site
|
||||||
component._location = self.device.location
|
component._location = self.device.location
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ def handle_location_site_change(instance, created, **kwargs):
|
|||||||
PowerPanel.objects.filter(location__in=locations).update(site=instance.site)
|
PowerPanel.objects.filter(location__in=locations).update(site=instance.site)
|
||||||
CableTermination.objects.filter(_location__in=locations).update(_site=instance.site)
|
CableTermination.objects.filter(_location__in=locations).update(_site=instance.site)
|
||||||
# Update component models for devices in these locations
|
# Update component models for devices in these locations
|
||||||
# (since Device.objects.update() doesn't trigger post_save signals)
|
|
||||||
for model in COMPONENT_MODELS:
|
for model in COMPONENT_MODELS:
|
||||||
model.objects.filter(device__location__in=locations).update(_site=instance.site)
|
model.objects.filter(device__location__in=locations).update(_site=instance.site)
|
||||||
|
|
||||||
@@ -58,7 +57,6 @@ def handle_rack_site_change(instance, created, **kwargs):
|
|||||||
if not created:
|
if not created:
|
||||||
Device.objects.filter(rack=instance).update(site=instance.site, location=instance.location)
|
Device.objects.filter(rack=instance).update(site=instance.site, location=instance.location)
|
||||||
# Update component models for devices in this rack
|
# Update component models for devices in this rack
|
||||||
# (since Device.objects.update() doesn't trigger post_save signals)
|
|
||||||
for model in COMPONENT_MODELS:
|
for model in COMPONENT_MODELS:
|
||||||
model.objects.filter(device__rack=instance).update(
|
model.objects.filter(device__rack=instance).update(
|
||||||
_site=instance.site,
|
_site=instance.site,
|
||||||
|
|||||||
@@ -76,36 +76,3 @@ def update_interface_bridges(device, interface_templates, module=None):
|
|||||||
)
|
)
|
||||||
interface.full_clean()
|
interface.full_clean()
|
||||||
interface.save()
|
interface.save()
|
||||||
|
|
||||||
|
|
||||||
def update_device_components(device):
|
|
||||||
"""
|
|
||||||
Update denormalized fields (_site, _location, _rack) for all component models
|
|
||||||
associated with the specified device.
|
|
||||||
|
|
||||||
:param device: Device instance whose components should be updated
|
|
||||||
"""
|
|
||||||
from dcim.models import (
|
|
||||||
ConsolePort, ConsoleServerPort, DeviceBay, FrontPort, Interface,
|
|
||||||
InventoryItem, ModuleBay, PowerOutlet, PowerPort, RearPort,
|
|
||||||
)
|
|
||||||
|
|
||||||
COMPONENT_MODELS = (
|
|
||||||
ConsolePort,
|
|
||||||
ConsoleServerPort,
|
|
||||||
DeviceBay,
|
|
||||||
FrontPort,
|
|
||||||
Interface,
|
|
||||||
InventoryItem,
|
|
||||||
ModuleBay,
|
|
||||||
PowerOutlet,
|
|
||||||
PowerPort,
|
|
||||||
RearPort,
|
|
||||||
)
|
|
||||||
|
|
||||||
for model in COMPONENT_MODELS:
|
|
||||||
model.objects.filter(device=device).update(
|
|
||||||
_site=device.site,
|
|
||||||
_location=device.location,
|
|
||||||
_rack=device.rack,
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user