mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Fixes #12118: Refactor bulk creation logic under _instantiate_components()
This commit is contained in:
parent
2bf9acfb19
commit
ccfdc216a5
@ -774,8 +774,10 @@ class Device(PrimaryModel, ConfigContextModel):
|
|||||||
bulk_create: If True, bulk_create() will be called to create all components in a single query
|
bulk_create: If True, bulk_create() will be called to create all components in a single query
|
||||||
(default). Otherwise, save() will be called on each instance individually.
|
(default). Otherwise, save() will be called on each instance individually.
|
||||||
"""
|
"""
|
||||||
components = [obj.instantiate(device=self) for obj in queryset]
|
if bulk_create:
|
||||||
if components and bulk_create:
|
components = [obj.instantiate(device=self) for obj in queryset]
|
||||||
|
if not components:
|
||||||
|
return
|
||||||
model = components[0]._meta.model
|
model = components[0]._meta.model
|
||||||
model.objects.bulk_create(components)
|
model.objects.bulk_create(components)
|
||||||
# Manually send the post_save signal for each of the newly created components
|
# Manually send the post_save signal for each of the newly created components
|
||||||
@ -788,8 +790,9 @@ class Device(PrimaryModel, ConfigContextModel):
|
|||||||
using='default',
|
using='default',
|
||||||
update_fields=None
|
update_fields=None
|
||||||
)
|
)
|
||||||
elif components:
|
else:
|
||||||
for component in components:
|
for obj in queryset:
|
||||||
|
component = obj.instantiate(device=self)
|
||||||
component.save()
|
component.save()
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user