1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Add brief_mode to DynamicModelChoiceMixin

This commit is contained in:
Jeremy Stretch
2020-08-12 14:15:34 -04:00
parent 5372492785
commit b891b407d4
6 changed files with 42 additions and 39 deletions

View File

@@ -251,16 +251,18 @@ class DynamicModelChoiceMixin:
:param null_option: The string used to represent a null selection (if any)
:param disabled_indicator: The name of the field which, if populated, will disable selection of the
choice (optional)
:param brief_mode: Use the "brief" format (?brief=true) when making API requests (default)
"""
filter = django_filters.ModelChoiceFilter
widget = widgets.APISelect
def __init__(self, *args, display_field='name', query_params=None, null_option=None, disabled_indicator=None,
**kwargs):
def __init__(self, display_field='name', query_params=None, null_option=None, disabled_indicator=None,
brief_mode=True, *args, **kwargs):
self.display_field = display_field
self.query_params = query_params or {}
self.null_option = null_option
self.disabled_indicator = disabled_indicator
self.brief_mode = brief_mode
# to_field_name is set by ModelChoiceField.__init__(), but we need to set it early for reference
# by widget_attrs()
@@ -285,6 +287,10 @@ class DynamicModelChoiceMixin:
if self.disabled_indicator is not None:
attrs['disabled-indicator'] = self.disabled_indicator
# Toggle brief mode
if not self.brief_mode:
attrs['data-full'] = 'true'
# Attach any static query parameters
for key, value in self.query_params.items():
widget.add_query_param(key, value)