mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Capture import form field default values
This commit is contained in:
parent
93154abb31
commit
47f1febfc9
@ -423,7 +423,17 @@ class ObjectImportView(GetReturnURLMixin, View):
|
||||
if form.is_valid():
|
||||
|
||||
# Initialize model form
|
||||
model_form = self.model_form(form.cleaned_data['data'])
|
||||
data = form.cleaned_data['data']
|
||||
model_form = self.model_form(data)
|
||||
|
||||
# Assign default values for any fields which were not specified. We have to do this manually because passing
|
||||
# 'initial=' to the form on initialization merely sets default values for the widgets. Since widgets are not
|
||||
# used for YAML/JSON import, we first bind the imported data normally, then update the form's data with the
|
||||
# applicable field defaults as needed prior to form validation.
|
||||
for field_name, field in model_form.fields.items():
|
||||
if field_name not in data and hasattr(field, 'initial'):
|
||||
model_form.data[field_name] = field.initial
|
||||
|
||||
if model_form.is_valid():
|
||||
|
||||
with transaction.atomic():
|
||||
|
Loading…
Reference in New Issue
Block a user