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)