mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 00:15:17 -06:00
Remove default setting for multi-select/multi-object and return slice of choices and annotate.
This commit is contained in:
parent
d2c32c9594
commit
9d6f69aa26
@ -275,8 +275,6 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|||||||
try:
|
try:
|
||||||
if self.type in (CustomFieldTypeChoices.TYPE_TEXT, CustomFieldTypeChoices.TYPE_LONGTEXT):
|
if self.type in (CustomFieldTypeChoices.TYPE_TEXT, CustomFieldTypeChoices.TYPE_LONGTEXT):
|
||||||
default_value = str(self.default)
|
default_value = str(self.default)
|
||||||
elif self.type in (CustomFieldTypeChoices.TYPE_MULTISELECT, CustomFieldTypeChoices.TYPE_MULTIOBJECT):
|
|
||||||
default_value = [self.default]
|
|
||||||
else:
|
else:
|
||||||
default_value = self.default
|
default_value = self.default
|
||||||
self.validate(default_value)
|
self.validate(default_value)
|
||||||
@ -655,8 +653,11 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|||||||
elif self.type == CustomFieldTypeChoices.TYPE_SELECT:
|
elif self.type == CustomFieldTypeChoices.TYPE_SELECT:
|
||||||
if value not in [c[0] for c in self.choices]:
|
if value not in [c[0] for c in self.choices]:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("Invalid choice ({value}). Available choices are: {choices}").format(
|
_("Invalid choice ({value}). Available choices are: {choices} ({count})")
|
||||||
value=value, choices=', '.join([c[0] for c in self.choices])
|
.format(
|
||||||
|
value=value,
|
||||||
|
choices=', '.join([c[0] for c in self.choices[0:2]]),
|
||||||
|
count=f'({len(self.choices)} choices)' if len(self.choices) > 2 else '',
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -664,8 +665,12 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|||||||
elif self.type == CustomFieldTypeChoices.TYPE_MULTISELECT:
|
elif self.type == CustomFieldTypeChoices.TYPE_MULTISELECT:
|
||||||
if not set(value).issubset([c[0] for c in self.choices]):
|
if not set(value).issubset([c[0] for c in self.choices]):
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("Invalid choice(s) ({invalid_choices}). Available choices are: {available_choices}").format(
|
_("Invalid choice(s) ({invalid_choices}). Available choices are: {available_choices}")
|
||||||
invalid_choices=', '.join(value), available_choices=', '.join([c[0] for c in self.choices]))
|
.format(
|
||||||
|
invalid_choices=', '.join(value),
|
||||||
|
available_choices=', '.join([c[0] for c in self.choices[0:2]]),
|
||||||
|
count=f'({len(self.choices)} choices)' if len(self.choices) > 2 else '',
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Validate selected object
|
# Validate selected object
|
||||||
|
Loading…
Reference in New Issue
Block a user