Skip to content

Commit 6efb258

Browse files
authored
Merge pull request #20908 from netbox-community/20068-import-moduletype-attrs
Closes #20068: Enable defining profile attributes when importing module types
2 parents da1e0f4 + ebf8f7f commit 6efb258

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

netbox/dcim/forms/bulk_import.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,14 +472,30 @@ class ModuleTypeImportForm(NetBoxModelImportForm):
472472
required=False,
473473
help_text=_('Unit for module weight')
474474
)
475+
attribute_data = forms.JSONField(
476+
label=_('Attributes'),
477+
required=False,
478+
help_text=_('Attribute values for the assigned profile, passed as a dictionary')
479+
)
475480

476481
class Meta:
477482
model = ModuleType
478483
fields = [
479484
'manufacturer', 'model', 'part_number', 'description', 'airflow', 'weight', 'weight_unit', 'profile',
480-
'comments', 'tags'
485+
'attribute_data', 'comments', 'tags',
481486
]
482487

488+
def clean(self):
489+
super().clean()
490+
491+
# Attribute data may be included only if a profile is specified
492+
if self.cleaned_data.get('attribute_data') and not self.cleaned_data.get('profile'):
493+
raise forms.ValidationError(_("Profile must be specified if attribute data is provided."))
494+
495+
# Default attribute_data to an empty dictionary if a profile is specified (to enforce schema validation)
496+
if self.cleaned_data.get('profile') and not self.cleaned_data.get('attribute_data'):
497+
self.cleaned_data['attribute_data'] = {}
498+
483499

484500
class DeviceRoleImportForm(NetBoxModelImportForm):
485501
parent = CSVModelChoiceField(

0 commit comments

Comments
 (0)