From 6d3cded57934327f3d4167069be41fde860ee7dd Mon Sep 17 00:00:00 2001 From: kkthxbye-code Date: Fri, 27 May 2022 20:41:50 +0200 Subject: [PATCH] Make sure initial data is passed as array for DynamicModelChoiceFields --- netbox/utilities/forms/fields/dynamic.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/netbox/utilities/forms/fields/dynamic.py b/netbox/utilities/forms/fields/dynamic.py index f83fc6a7c..dc3bab9fc 100644 --- a/netbox/utilities/forms/fields/dynamic.py +++ b/netbox/utilities/forms/fields/dynamic.py @@ -88,7 +88,12 @@ class DynamicModelChoiceMixin: # Modify the QuerySet of the field before we return it. Limit choices to any data already bound: Options # will be populated on-demand via the APISelect widget. data = bound_field.value() + if data: + # When the field is multiple choice pass the data as a list if it's not already + if isinstance(bound_field.field, DynamicModelMultipleChoiceField) and not type(data) is list: + data = [data] + field_name = getattr(self, 'to_field_name') or 'pk' filter = self.filter(field_name=field_name) try: