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

Remove value_field from APISelect; reference to_field_name on field

This commit is contained in:
Jeremy Stretch
2020-08-11 17:19:40 -04:00
parent fdc43f8279
commit a831e525da
9 changed files with 30 additions and 136 deletions

View File

@@ -251,12 +251,19 @@ class DynamicModelChoiceMixin:
def __init__(self, *args, display_field='name', **kwargs):
self.display_field = display_field
# to_field_name is set by ModelChoiceField.__init__(), but we need to set it early for reference
# by widget_attrs()
self.to_field_name = kwargs.get('to_field_name')
super().__init__(*args, **kwargs)
def widget_attrs(self, widget):
return {
'display-field': self.display_field
attrs = {
'display-field': self.display_field,
}
if self.to_field_name:
attrs['value-field'] = self.to_field_name
return attrs
def get_bound_field(self, form, field_name):
bound_field = BoundField(form, self, field_name)

View File

@@ -141,7 +141,6 @@ class APISelect(SelectWithDisabled):
:param api_url: API endpoint URL. Required if not set automatically by the parent field.
:param display_field: (Optional) Field to display for child in selection list. Defaults to `name`.
:param value_field: (Optional) Field to use for the option value in selection list. Defaults to `id`.
:param disabled_indicator: (Optional) Mark option as disabled if this field equates true.
:param filter_for: (Optional) A dict of chained form fields for which this field is a filter. The key is the
name of the filter-for field (child field) and the value is the name of the query param filter.
@@ -153,7 +152,6 @@ class APISelect(SelectWithDisabled):
self,
api_url=None,
display_field=None,
value_field=None,
disabled_indicator=None,
filter_for=None,
additional_query_params=None,
@@ -172,8 +170,6 @@ class APISelect(SelectWithDisabled):
self.attrs['data-full'] = full
if display_field:
self.attrs['display-field'] = display_field
if value_field:
self.attrs['value-field'] = value_field
if disabled_indicator:
self.attrs['disabled-indicator'] = disabled_indicator
if filter_for: