Skip to content

Commit

Permalink
Fixes: #17820 - Store default values from custom fields on newly crea…
Browse files Browse the repository at this point in the history
…ted module components (#18084)

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

* Invert if/for lines to avoid repetition
  • Loading branch information
bctiemann authored Dec 11, 2024
1 parent 001f06c commit cc51e70
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions netbox/dcim/models/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,11 @@ def save(self, *args, **kwargs):
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
Expand Down

0 comments on commit cc51e70

Please sign in to comment.