Skip to content

Commit

Permalink
Closes #5399: Show options for cable endpoint types during bulk import
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Dec 2, 2020
1 parent cc271ae commit 2b0ddd2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/version-2.10.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancements

* [#5274](https://github.com/netbox-community/netbox/issues/5274) - Add REST API support for custom fields
* [#5399](https://github.com/netbox-community/netbox/issues/5399) - Show options for cable endpoint types during bulk import

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/generic/object_bulk_import.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h1>{% block title %}{{ obj_type|bettertitle }} Bulk Import{% endblock %}</h1>
</td>
<td>
{% if field.STATIC_CHOICES %}
<button type="button" class="btn btn-primary btn-xs pull-right" data-toggle="modal" data-target="#{{ name }}_choices">
<button type="button" class="btn btn-link btn-xs pull-right" data-toggle="modal" data-target="#{{ name }}_choices">
<i class="mdi mdi-help-circle"></i>
</button>
<div class="modal fade" id="{{ name }}_choices" tabindex="-1" role="dialog">
Expand Down
9 changes: 8 additions & 1 deletion netbox/utilities/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,20 @@ class CSVModelChoiceField(forms.ModelChoiceField):
def to_python(self, value):
try:
return super().to_python(value)
except MultipleObjectsReturned as e:
except MultipleObjectsReturned:
raise forms.ValidationError(
f'"{value}" is not a unique value for this field; multiple objects were found'
)


class CSVContentTypeField(CSVModelChoiceField):
"""
Reference a ContentType in the form <app>.<model>
"""
STATIC_CHOICES = True

def prepare_value(self, value):
return f'{value.app_label}.{value.model}'

def to_python(self, value):
try:
Expand Down

0 comments on commit 2b0ddd2

Please sign in to comment.