mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
* Add handling for FieldError to CSVModelChoiceField.to_python to handle invalid accessor field * manufacturer & default_platform should be CSVModelChoiceFields * Fix string translation --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
parent
0ec632e548
commit
52a0b454c0
@ -373,7 +373,7 @@ class DeviceTypeImportForm(NetBoxModelImportForm):
|
|||||||
to_field_name='name',
|
to_field_name='name',
|
||||||
help_text=_('The manufacturer which produces this device type')
|
help_text=_('The manufacturer which produces this device type')
|
||||||
)
|
)
|
||||||
default_platform = forms.ModelChoiceField(
|
default_platform = CSVModelChoiceField(
|
||||||
label=_('Default platform'),
|
label=_('Default platform'),
|
||||||
queryset=Platform.objects.all(),
|
queryset=Platform.objects.all(),
|
||||||
to_field_name='name',
|
to_field_name='name',
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
|
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist, FieldError
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
from utilities.choices import unpack_grouped_choices
|
from utilities.choices import unpack_grouped_choices
|
||||||
@ -64,6 +64,10 @@ class CSVModelChoiceField(forms.ModelChoiceField):
|
|||||||
raise forms.ValidationError(
|
raise forms.ValidationError(
|
||||||
_('"{value}" is not a unique value for this field; multiple objects were found').format(value=value)
|
_('"{value}" is not a unique value for this field; multiple objects were found').format(value=value)
|
||||||
)
|
)
|
||||||
|
except FieldError:
|
||||||
|
raise forms.ValidationError(
|
||||||
|
_('"{field_name}" is an invalid accessor field name.').format(field_name=self.to_field_name)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CSVModelMultipleChoiceField(forms.ModelMultipleChoiceField):
|
class CSVModelMultipleChoiceField(forms.ModelMultipleChoiceField):
|
||||||
|
Loading…
Reference in New Issue
Block a user