mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #5990: Deprecated display_field parameter for custom script ObjectVar and MultiObjectVar fields
This commit is contained in:
@@ -180,14 +180,22 @@ 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 (default: 'name')
|
||||
: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=None, queryset=None, display_field='name', query_params=None, null_option=None, *args,
|
||||
**kwargs):
|
||||
def __init__(self, model=None, queryset=None, 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)
|
||||
|
||||
# Set the form field's queryset. Support backward compatibility for the "queryset" argument for now.
|
||||
|
@@ -276,6 +276,7 @@ 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, brief_mode=True, *args, **kwargs):
|
||||
self.display_field = display_field
|
||||
|
Reference in New Issue
Block a user