Fixes: #17820 - Store default values from custom fields on newly created module components (#18084)

* Store default values from custom fields on newly created module components

* Invert if/for lines to avoid repetition
This commit is contained in:
bctiemann 2024-12-11 09:14:17 -05:00 committed by GitHub
parent 001f06cc9a
commit cc51e7032b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1277,6 +1277,11 @@ class Module(PrimaryModel, ConfigContextModel):
if not disable_replication:
create_instances.append(template_instance)
# Set default values for any applicable custom fields
if cf_defaults := CustomField.objects.get_defaults_for_model(component_model):
for component in create_instances:
component.custom_field_data = cf_defaults
if component_model is not ModuleBay:
component_model.objects.bulk_create(create_instances)
# Emit the post_save signal for each newly created object