2👍
✅
This is already the case, since you did not specify blank=True
[Django-doc], this means that the form field is required, so this means that for the form field, required=True
[Django-doc], and for a BooleanField
form field [Django-doc], this means:
Since all Field subclasses have
required=True
by default, the validation condition here is important. If you want to include a boolean in your form that can be eitherTrue
orFalse
(e.g. a checked or unchecked checkbox), you must remember to pass inrequired=False
when creating theBooleanField
.
You thus can simply let Django do the work:
class CheckForm(forms.ModelForm):
translated_names = TranslationField()
# no clean override
class Meta:
model = models.Check
fields = '__all__'
Source:stackexchange.com