Required Boolean Field?

I have a logical field,

is_operable = BooleanField(widget=RadioSelect(choices=YES_OR_NO, renderer=InlineRadioFieldRenderer), required=False, initial=True)

Which is displayed as two radio buttons (yes or no), but I want this to be necessary. The problem is that if I change it to required=True, it throws a validation error when it receives False.

Is there any way around this?


YES_OR_NO = (
    (True, 'Yes'),
    (False, 'No')
)
+4
source share
2 answers

I would recommend using TypedChoiceFieldone that forces the choice YES_OR_NOto logical. See Docs: http://docs.djangoproject.com/en/1.2/ref/forms/fields/#django.forms.TypedChoiceField

+3
source

required=False clean_is_operable, , , , ValidationError

+3

Source: https://habr.com/ru/post/1758117/


All Articles