mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
7376 csv tags (#10802)
* 7376 add tags to CSV import * 7376 change help text * 7376 validate tags * 7376 fix tests * 7376 add tag validation tests * Introduce CSVModelMultipleChoiceField for CSV import tag assignment * Clean up CSVImportTestCase Co-authored-by: jeremystretch <jstretch@ns1.com>
This commit is contained in:
@@ -16,6 +16,7 @@ __all__ = (
|
||||
'CSVDataField',
|
||||
'CSVFileField',
|
||||
'CSVModelChoiceField',
|
||||
'CSVModelMultipleChoiceField',
|
||||
'CSVMultipleChoiceField',
|
||||
'CSVMultipleContentTypeField',
|
||||
'CSVTypedChoiceField',
|
||||
@@ -142,7 +143,7 @@ class CSVModelChoiceField(forms.ModelChoiceField):
|
||||
Extends Django's `ModelChoiceField` to provide additional validation for CSV values.
|
||||
"""
|
||||
default_error_messages = {
|
||||
'invalid_choice': 'Object not found.',
|
||||
'invalid_choice': 'Object not found: %(value)s',
|
||||
}
|
||||
|
||||
def to_python(self, value):
|
||||
@@ -154,6 +155,19 @@ class CSVModelChoiceField(forms.ModelChoiceField):
|
||||
)
|
||||
|
||||
|
||||
class CSVModelMultipleChoiceField(forms.ModelMultipleChoiceField):
|
||||
"""
|
||||
Extends Django's `ModelMultipleChoiceField` to support comma-separated values.
|
||||
"""
|
||||
default_error_messages = {
|
||||
'invalid_choice': 'Object not found: %(value)s',
|
||||
}
|
||||
|
||||
def clean(self, value):
|
||||
value = value.split(',') if value else []
|
||||
return super().clean(value)
|
||||
|
||||
|
||||
class CSVContentTypeField(CSVModelChoiceField):
|
||||
"""
|
||||
CSV field for referencing a single content type, in the form `<app>.<model>`.
|
||||
|
Reference in New Issue
Block a user