mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #1860: Do not populate initial values for custom fields when editing objects in bulk
This commit is contained in:
@ -22,10 +22,11 @@ def get_custom_fields_for_model(content_type, filterable_only=False, bulk_edit=F
|
|||||||
|
|
||||||
for cf in custom_fields:
|
for cf in custom_fields:
|
||||||
field_name = 'cf_{}'.format(str(cf.name))
|
field_name = 'cf_{}'.format(str(cf.name))
|
||||||
|
initial = cf.default if not bulk_edit else None
|
||||||
|
|
||||||
# Integer
|
# Integer
|
||||||
if cf.type == CF_TYPE_INTEGER:
|
if cf.type == CF_TYPE_INTEGER:
|
||||||
field = forms.IntegerField(required=cf.required, initial=cf.default)
|
field = forms.IntegerField(required=cf.required, initial=initial)
|
||||||
|
|
||||||
# Boolean
|
# Boolean
|
||||||
elif cf.type == CF_TYPE_BOOLEAN:
|
elif cf.type == CF_TYPE_BOOLEAN:
|
||||||
@ -34,18 +35,19 @@ def get_custom_fields_for_model(content_type, filterable_only=False, bulk_edit=F
|
|||||||
(1, 'True'),
|
(1, 'True'),
|
||||||
(0, 'False'),
|
(0, 'False'),
|
||||||
)
|
)
|
||||||
if cf.default.lower() in ['true', 'yes', '1']:
|
if initial.lower() in ['true', 'yes', '1']:
|
||||||
initial = 1
|
initial = 1
|
||||||
elif cf.default.lower() in ['false', 'no', '0']:
|
elif initial.lower() in ['false', 'no', '0']:
|
||||||
initial = 0
|
initial = 0
|
||||||
else:
|
else:
|
||||||
initial = None
|
initial = None
|
||||||
field = forms.NullBooleanField(required=cf.required, initial=initial,
|
field = forms.NullBooleanField(
|
||||||
widget=forms.Select(choices=choices))
|
required=cf.required, initial=initial, widget=forms.Select(choices=choices)
|
||||||
|
)
|
||||||
|
|
||||||
# Date
|
# Date
|
||||||
elif cf.type == CF_TYPE_DATE:
|
elif cf.type == CF_TYPE_DATE:
|
||||||
field = forms.DateField(required=cf.required, initial=cf.default, help_text="Date format: YYYY-MM-DD")
|
field = forms.DateField(required=cf.required, initial=initial, help_text="Date format: YYYY-MM-DD")
|
||||||
|
|
||||||
# Select
|
# Select
|
||||||
elif cf.type == CF_TYPE_SELECT:
|
elif cf.type == CF_TYPE_SELECT:
|
||||||
@ -56,11 +58,11 @@ def get_custom_fields_for_model(content_type, filterable_only=False, bulk_edit=F
|
|||||||
|
|
||||||
# URL
|
# URL
|
||||||
elif cf.type == CF_TYPE_URL:
|
elif cf.type == CF_TYPE_URL:
|
||||||
field = LaxURLField(required=cf.required, initial=cf.default)
|
field = LaxURLField(required=cf.required, initial=initial)
|
||||||
|
|
||||||
# Text
|
# Text
|
||||||
else:
|
else:
|
||||||
field = forms.CharField(max_length=255, required=cf.required, initial=cf.default)
|
field = forms.CharField(max_length=255, required=cf.required, initial=initial)
|
||||||
|
|
||||||
field.model = cf
|
field.model = cf
|
||||||
field.label = cf.label if cf.label else cf.name.replace('_', ' ').capitalize()
|
field.label = cf.label if cf.label else cf.name.replace('_', ' ').capitalize()
|
||||||
|
Reference in New Issue
Block a user