mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 09:28:38 -06:00
Account for initial data when binding a DynamicModelChoiceField
This commit is contained in:
parent
221805a63e
commit
fb56d5bc66
@ -562,10 +562,11 @@ class DynamicModelChoiceField(forms.ModelChoiceField):
|
|||||||
|
|
||||||
# Modify the QuerySet of the field before we return it. Limit choices to any data already bound: Options
|
# 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.
|
# will be populated on-demand via the APISelect widget.
|
||||||
|
field_name = '{}{}'.format(self.to_field_name or 'pk', self.field_modifier)
|
||||||
if bound_field.data:
|
if bound_field.data:
|
||||||
field_name = '{}{}'.format(self.to_field_name or 'pk', self.field_modifier)
|
self.queryset = self.queryset.filter(**{field_name: bound_field.data})
|
||||||
kwargs = {field_name: bound_field.data}
|
elif bound_field.initial:
|
||||||
self.queryset = self.queryset.filter(**kwargs)
|
self.queryset = self.queryset.filter(**{field_name: bound_field.initial})
|
||||||
else:
|
else:
|
||||||
self.queryset = self.queryset.none()
|
self.queryset = self.queryset.none()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user