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

Add display_field kwarg to DynamicModelChoiceMixin

This commit is contained in:
Jeremy Stretch
2020-08-11 17:00:28 -04:00
parent 2c64d45c69
commit fdc43f8279
5 changed files with 40 additions and 45 deletions

View File

@@ -11,6 +11,7 @@ from django.db.models import Count
from django.forms import BoundField
from django.urls import reverse
from utilities.api import get_serializer_for_model
from utilities.choices import unpack_grouped_choices
from utilities.validators import EnhancedURLValidator
from . import widgets
@@ -247,6 +248,16 @@ class DynamicModelChoiceMixin:
filter = django_filters.ModelChoiceFilter
widget = widgets.APISelect
def __init__(self, *args, display_field='name', **kwargs):
self.display_field = display_field
super().__init__(*args, **kwargs)
def widget_attrs(self, widget):
return {
'display-field': self.display_field
}
def get_bound_field(self, form, field_name):
bound_field = BoundField(form, self, field_name)