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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user