Skip to content

Commit 9476fda

Browse files
committed
Closes #5994: Drop support for display_field argument on ObjectVar
1 parent b509d96 commit 9476fda

File tree

6 files changed

+6
-29
lines changed

6 files changed

+6
-29
lines changed

docs/additional-features/custom-scripts.md

-6
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,9 @@ Similar to `ChoiceVar`, but allows for the selection of multiple choices.
170170
A particular object within NetBox. Each ObjectVar must specify a particular model, and allows the user to select one of the available instances. ObjectVar accepts several arguments, listed below.
171171

172172
* `model` - The model class
173-
* `display_field` - The name of the REST API object field to display in the selection list (default: `'display'`)
174173
* `query_params` - A dictionary of query parameters to use when retrieving available options (optional)
175174
* `null_option` - A label representing a "null" or empty choice (optional)
176175

177-
!!! warning
178-
The `display_field` parameter is now deprecated, and will be removed in NetBox v2.12. All ObjectVar instances will
179-
instead use the new standard `display` field for all serializers (introduced in NetBox v2.11).
180-
181176
To limit the selections available within the list, additional query parameters can be passed as the `query_params` dictionary. For example, to show only devices with an "active" status:
182177

183178
```python
@@ -288,7 +283,6 @@ class NewBranchScript(Script):
288283
switch_model = ObjectVar(
289284
description="Access switch model",
290285
model=DeviceType,
291-
display_field='model',
292286
query_params={
293287
'manufacturer_id': '$manufacturer'
294288
}

docs/release-notes/version-2.12.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
### Other Changes
66

77
* [#5532](https://github.com/netbox-community/netbox/issues/5532) - Drop support for Python 3.6
8+
* [#5994](https://github.com/netbox-community/netbox/issues/5994) - Drop support for `display_field` argument on ObjectVar

netbox/extras/scripts.py

-11
Original file line numberDiff line numberDiff line change
@@ -180,27 +180,16 @@ class ObjectVar(ScriptVariable):
180180
A single object within NetBox.
181181
182182
:param model: The NetBox model being referenced
183-
:param display_field: The attribute of the returned object to display in the selection list (DEPRECATED)
184183
:param query_params: A dictionary of additional query parameters to attach when making REST API requests (optional)
185184
:param null_option: The label to use as a "null" selection option (optional)
186185
"""
187186
form_field = DynamicModelChoiceField
188187

189188
def __init__(self, model, query_params=None, null_option=None, *args, **kwargs):
190-
191-
# TODO: Remove display_field in v2.12
192-
if 'display_field' in kwargs:
193-
warnings.warn(
194-
"The 'display_field' parameter has been deprecated, and will be removed in NetBox v2.12. Object "
195-
"variables will now reference the 'display' attribute available on all model serializers by default."
196-
)
197-
display_field = kwargs.pop('display_field', 'display')
198-
199189
super().__init__(*args, **kwargs)
200190

201191
self.field_attrs.update({
202192
'queryset': model.objects.all(),
203-
'display_field': display_field,
204193
'query_params': query_params,
205194
'null_option': null_option,
206195
})

netbox/project-static/js/forms.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ $(document).ready(function() {
201201
var results = data.results;
202202

203203
results = results.reduce((results,record,idx) => {
204-
record.text = record[element.getAttribute('display-field')] || record.name;
204+
record.text = record.display;
205205
if (record._depth) {
206206
// Annotate hierarchical depth for MPTT objects
207207
record.text = '--'.repeat(record._depth) + ' ' + record.text;

netbox/utilities/forms/fields.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ def to_python(self, value):
328328

329329
class DynamicModelChoiceMixin:
330330
"""
331-
:param display_field: The name of the attribute of an API response object to display in the selection list
332331
:param query_params: A dictionary of additional key/value pairs to attach to the API request
333332
:param initial_params: A dictionary of child field references to use for selecting a parent field's initial value
334333
:param null_option: The string used to represent a null selection (if any)
@@ -338,10 +337,8 @@ class DynamicModelChoiceMixin:
338337
filter = django_filters.ModelChoiceFilter
339338
widget = widgets.APISelect
340339

341-
# TODO: Remove display_field in v2.12
342-
def __init__(self, display_field='display', query_params=None, initial_params=None, null_option=None,
343-
disabled_indicator=None, *args, **kwargs):
344-
self.display_field = display_field
340+
def __init__(self, query_params=None, initial_params=None, null_option=None, disabled_indicator=None, *args,
341+
**kwargs):
345342
self.query_params = query_params or {}
346343
self.initial_params = initial_params or {}
347344
self.null_option = null_option
@@ -354,9 +351,7 @@ def __init__(self, display_field='display', query_params=None, initial_params=No
354351
super().__init__(*args, **kwargs)
355352

356353
def widget_attrs(self, widget):
357-
attrs = {
358-
'display-field': self.display_field,
359-
}
354+
attrs = {}
360355

361356
# Set value-field attribute if the field specifies to_field_name
362357
if self.to_field_name:

netbox/virtualization/forms.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ class VMInterfaceCreateForm(BootstrapMixin, InterfaceCommonForm):
667667
parent = DynamicModelChoiceField(
668668
queryset=VMInterface.objects.all(),
669669
required=False,
670-
display_field='display_name',
671670
query_params={
672671
'virtualmachine_id': 'virtual_machine',
673672
}
@@ -756,8 +755,7 @@ class VMInterfaceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, BulkEditForm):
756755
)
757756
parent = DynamicModelChoiceField(
758757
queryset=VMInterface.objects.all(),
759-
required=False,
760-
display_field='display_name'
758+
required=False
761759
)
762760
enabled = forms.NullBooleanField(
763761
required=False,

0 commit comments

Comments
 (0)