From 3d2f6c07031d0abbd8c08f304f7b5665ece9106b Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 17 Sep 2020 12:26:02 -0400 Subject: [PATCH] Simplify form field for boolean CustomFields --- netbox/extras/models/customfields.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/netbox/extras/models/customfields.py b/netbox/extras/models/customfields.py index eac481bef..bb577fd4b 100644 --- a/netbox/extras/models/customfields.py +++ b/netbox/extras/models/customfields.py @@ -159,15 +159,11 @@ class CustomField(models.Model): elif self.type == CustomFieldTypeChoices.TYPE_BOOLEAN: choices = ( (None, '---------'), - (1, 'True'), - (0, 'False'), + (True, 'True'), + (False, 'False'), ) - if initial is not None and initial.lower() in ['true', 'yes', '1']: - initial = 1 - elif initial is not None and initial.lower() in ['false', 'no', '0']: - initial = 0 - else: - initial = None + if initial is not None: + initial = bool(initial) field = forms.NullBooleanField( required=required, initial=initial, widget=StaticSelect2(choices=choices) )