mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-09 13:22:18 -06:00
This commit is contained in:
@@ -957,6 +957,11 @@ 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
|
||||||
|
for component in components:
|
||||||
|
component._site = self.site
|
||||||
|
component._location = self.location
|
||||||
|
component._rack = self.rack
|
||||||
components = model.objects.bulk_create(components)
|
components = model.objects.bulk_create(components)
|
||||||
# Prefetch related objects to minimize queries needed during post_save
|
# Prefetch related objects to minimize queries needed during post_save
|
||||||
prefetch_fields = get_prefetchable_fields(model)
|
prefetch_fields = get_prefetchable_fields(model)
|
||||||
|
|||||||
@@ -315,6 +315,12 @@ 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
|
||||||
|
for component in create_instances:
|
||||||
|
component._site = self.device.site
|
||||||
|
component._location = self.device.location
|
||||||
|
component._rack = self.device.rack
|
||||||
|
|
||||||
if component_model is not ModuleBay:
|
if component_model is not ModuleBay:
|
||||||
component_model.objects.bulk_create(create_instances)
|
component_model.objects.bulk_create(create_instances)
|
||||||
# Emit the post_save signal for each newly created object
|
# Emit the post_save signal for each newly created object
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ def handle_location_site_change(instance, created, **kwargs):
|
|||||||
Device.objects.filter(location__in=locations).update(site=instance.site)
|
Device.objects.filter(location__in=locations).update(site=instance.site)
|
||||||
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
|
||||||
|
for model in COMPONENT_MODELS:
|
||||||
|
model.objects.filter(device__location__in=locations).update(_site=instance.site)
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Rack)
|
@receiver(post_save, sender=Rack)
|
||||||
@@ -53,6 +56,12 @@ 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
|
||||||
|
for model in COMPONENT_MODELS:
|
||||||
|
model.objects.filter(device__rack=instance).update(
|
||||||
|
_site=instance.site,
|
||||||
|
_location=instance.location,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=Device)
|
@receiver(post_save, sender=Device)
|
||||||
|
|||||||
Reference in New Issue
Block a user