From 0f0010bac0855e146f21522be94fa9148d7220e3 Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Wed, 27 Jan 2021 09:21:00 -0600 Subject: [PATCH] Fixes: #5315 - Make "null_option" on DynamicModelChoiceField also null the value on the model. --- docs/release-notes/version-2.10.md | 8 ++++++++ netbox/utilities/forms/fields.py | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-2.10.md b/docs/release-notes/version-2.10.md index b6bc33229..f5e0b4fa2 100644 --- a/docs/release-notes/version-2.10.md +++ b/docs/release-notes/version-2.10.md @@ -1,5 +1,13 @@ # NetBox v2.10 +## v2.10.5 (FUTURE) + +### Bug Fixes + +* [#5315](https://github.com/netbox-community/netbox/issues/5315) - Fix site unassignment from VLAN when using "None" option + +--- + ## v2.10.4 (2021-01-26) ### Enhancements diff --git a/netbox/utilities/forms/fields.py b/netbox/utilities/forms/fields.py index a5b76fd8d..3cf421213 100644 --- a/netbox/utilities/forms/fields.py +++ b/netbox/utilities/forms/fields.py @@ -355,7 +355,11 @@ class DynamicModelChoiceField(DynamicModelChoiceMixin, forms.ModelChoiceField): Override get_bound_field() to avoid pre-populating field choices with a SQL query. The field will be rendered only with choices set via bound data. Choices are populated on-demand via the APISelect widget. """ - pass + + def clean(self, value): + if self.null_option is not None and value == 'null': + return None + return super().clean(value) class DynamicModelMultipleChoiceField(DynamicModelChoiceMixin, forms.ModelMultipleChoiceField):