diff --git a/docs/release-notes/version-3.4.md b/docs/release-notes/version-3.4.md index b7ca6b27c..5134c9972 100644 --- a/docs/release-notes/version-3.4.md +++ b/docs/release-notes/version-3.4.md @@ -2,6 +2,10 @@ ## v3.4.4 (FUTURE) +### Enhancements + +* [#10762](https://github.com/netbox-community/netbox/issues/10762) - Permit selection custom fields to have only one choice + ### Bug Fixes * [#11487](https://github.com/netbox-community/netbox/issues/11487) - Remove "set null" option from non-writable custom fields during bulk edit diff --git a/netbox/extras/models/customfields.py b/netbox/extras/models/customfields.py index 14b033bcd..4842c0654 100644 --- a/netbox/extras/models/customfields.py +++ b/netbox/extras/models/customfields.py @@ -273,10 +273,13 @@ class CustomField(CloningMixin, ExportTemplatesMixin, WebhooksMixin, ChangeLogge 'choices': "Choices may be set only for custom selection fields." }) - # A selection field must have at least two choices defined - if self.type == CustomFieldTypeChoices.TYPE_SELECT and self.choices and len(self.choices) < 2: + # Selection fields must have at least one choice defined + if self.type in ( + CustomFieldTypeChoices.TYPE_SELECT, + CustomFieldTypeChoices.TYPE_MULTISELECT + ) and not self.choices: raise ValidationError({ - 'choices': "Selection fields must specify at least two choices." + 'choices': "Selection fields must specify at least one choice." }) # A selection field's default (if any) must be present in its available choices diff --git a/netbox/extras/tests/test_api.py b/netbox/extras/tests/test_api.py index 29e725507..81a607eec 100644 --- a/netbox/extras/tests/test_api.py +++ b/netbox/extras/tests/test_api.py @@ -101,6 +101,7 @@ class CustomFieldTest(APIViewTestCases.APIViewTestCase): 'content_types': ['dcim.site'], 'name': 'cf6', 'type': 'select', + 'choices': ['A', 'B', 'C'] }, ] bulk_update_data = {