mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Closes #5994: Drop support for display_field argument on ObjectVar
This commit is contained in:
parent
b509d96f18
commit
9476fda987
@ -170,14 +170,9 @@ Similar to `ChoiceVar`, but allows for the selection of multiple choices.
|
||||
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.
|
||||
|
||||
* `model` - The model class
|
||||
* `display_field` - The name of the REST API object field to display in the selection list (default: `'display'`)
|
||||
* `query_params` - A dictionary of query parameters to use when retrieving available options (optional)
|
||||
* `null_option` - A label representing a "null" or empty choice (optional)
|
||||
|
||||
!!! warning
|
||||
The `display_field` parameter is now deprecated, and will be removed in NetBox v2.12. All ObjectVar instances will
|
||||
instead use the new standard `display` field for all serializers (introduced in NetBox v2.11).
|
||||
|
||||
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:
|
||||
|
||||
```python
|
||||
@ -288,7 +283,6 @@ class NewBranchScript(Script):
|
||||
switch_model = ObjectVar(
|
||||
description="Access switch model",
|
||||
model=DeviceType,
|
||||
display_field='model',
|
||||
query_params={
|
||||
'manufacturer_id': '$manufacturer'
|
||||
}
|
||||
|
@ -5,3 +5,4 @@
|
||||
### Other Changes
|
||||
|
||||
* [#5532](https://github.com/netbox-community/netbox/issues/5532) - Drop support for Python 3.6
|
||||
* [#5994](https://github.com/netbox-community/netbox/issues/5994) - Drop support for `display_field` argument on ObjectVar
|
||||
|
@ -180,27 +180,16 @@ class ObjectVar(ScriptVariable):
|
||||
A single object within NetBox.
|
||||
|
||||
:param model: The NetBox model being referenced
|
||||
:param display_field: The attribute of the returned object to display in the selection list (DEPRECATED)
|
||||
:param query_params: A dictionary of additional query parameters to attach when making REST API requests (optional)
|
||||
:param null_option: The label to use as a "null" selection option (optional)
|
||||
"""
|
||||
form_field = DynamicModelChoiceField
|
||||
|
||||
def __init__(self, model, query_params=None, null_option=None, *args, **kwargs):
|
||||
|
||||
# TODO: Remove display_field in v2.12
|
||||
if 'display_field' in kwargs:
|
||||
warnings.warn(
|
||||
"The 'display_field' parameter has been deprecated, and will be removed in NetBox v2.12. Object "
|
||||
"variables will now reference the 'display' attribute available on all model serializers by default."
|
||||
)
|
||||
display_field = kwargs.pop('display_field', 'display')
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.field_attrs.update({
|
||||
'queryset': model.objects.all(),
|
||||
'display_field': display_field,
|
||||
'query_params': query_params,
|
||||
'null_option': null_option,
|
||||
})
|
||||
|
@ -201,7 +201,7 @@ $(document).ready(function() {
|
||||
var results = data.results;
|
||||
|
||||
results = results.reduce((results,record,idx) => {
|
||||
record.text = record[element.getAttribute('display-field')] || record.name;
|
||||
record.text = record.display;
|
||||
if (record._depth) {
|
||||
// Annotate hierarchical depth for MPTT objects
|
||||
record.text = '--'.repeat(record._depth) + ' ' + record.text;
|
||||
|
@ -328,7 +328,6 @@ class ExpandableIPAddressField(forms.CharField):
|
||||
|
||||
class DynamicModelChoiceMixin:
|
||||
"""
|
||||
:param display_field: The name of the attribute of an API response object to display in the selection list
|
||||
:param query_params: A dictionary of additional key/value pairs to attach to the API request
|
||||
:param initial_params: A dictionary of child field references to use for selecting a parent field's initial value
|
||||
:param null_option: The string used to represent a null selection (if any)
|
||||
@ -338,10 +337,8 @@ class DynamicModelChoiceMixin:
|
||||
filter = django_filters.ModelChoiceFilter
|
||||
widget = widgets.APISelect
|
||||
|
||||
# TODO: Remove display_field in v2.12
|
||||
def __init__(self, display_field='display', query_params=None, initial_params=None, null_option=None,
|
||||
disabled_indicator=None, *args, **kwargs):
|
||||
self.display_field = display_field
|
||||
def __init__(self, query_params=None, initial_params=None, null_option=None, disabled_indicator=None, *args,
|
||||
**kwargs):
|
||||
self.query_params = query_params or {}
|
||||
self.initial_params = initial_params or {}
|
||||
self.null_option = null_option
|
||||
@ -354,9 +351,7 @@ class DynamicModelChoiceMixin:
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def widget_attrs(self, widget):
|
||||
attrs = {
|
||||
'display-field': self.display_field,
|
||||
}
|
||||
attrs = {}
|
||||
|
||||
# Set value-field attribute if the field specifies to_field_name
|
||||
if self.to_field_name:
|
||||
|
@ -667,7 +667,6 @@ class VMInterfaceCreateForm(BootstrapMixin, InterfaceCommonForm):
|
||||
parent = DynamicModelChoiceField(
|
||||
queryset=VMInterface.objects.all(),
|
||||
required=False,
|
||||
display_field='display_name',
|
||||
query_params={
|
||||
'virtualmachine_id': 'virtual_machine',
|
||||
}
|
||||
@ -756,8 +755,7 @@ class VMInterfaceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, BulkEditForm):
|
||||
)
|
||||
parent = DynamicModelChoiceField(
|
||||
queryset=VMInterface.objects.all(),
|
||||
required=False,
|
||||
display_field='display_name'
|
||||
required=False
|
||||
)
|
||||
enabled = forms.NullBooleanField(
|
||||
required=False,
|
||||
|
Loading…
Reference in New Issue
Block a user