mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-19 05:21:55 -06:00
Simplify form field for boolean CustomFields
This commit is contained in:
parent
4ecd3d23f7
commit
3d2f6c0703
@ -159,15 +159,11 @@ class CustomField(models.Model):
|
|||||||
elif self.type == CustomFieldTypeChoices.TYPE_BOOLEAN:
|
elif self.type == CustomFieldTypeChoices.TYPE_BOOLEAN:
|
||||||
choices = (
|
choices = (
|
||||||
(None, '---------'),
|
(None, '---------'),
|
||||||
(1, 'True'),
|
(True, 'True'),
|
||||||
(0, 'False'),
|
(False, 'False'),
|
||||||
)
|
)
|
||||||
if initial is not None and initial.lower() in ['true', 'yes', '1']:
|
if initial is not None:
|
||||||
initial = 1
|
initial = bool(initial)
|
||||||
elif initial is not None and initial.lower() in ['false', 'no', '0']:
|
|
||||||
initial = 0
|
|
||||||
else:
|
|
||||||
initial = None
|
|
||||||
field = forms.NullBooleanField(
|
field = forms.NullBooleanField(
|
||||||
required=required, initial=initial, widget=StaticSelect2(choices=choices)
|
required=required, initial=initial, widget=StaticSelect2(choices=choices)
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user