[Answered ]-Raise error if the input is False (Boolean) while uploading excel sheet via import_export in Django Form

1👍

You can either:

Override each of the boolean fields in the form

… with a boolean field that has required=True:

class add_to_database(forms.ModelForm):
    village_covered = forms.BooleanField(..., required=True)
    # (repeat for other boolean fields that are required)

    class Meta:
        ...

Or add validation functions:

class add_to_database(forms.ModelForm):
    ...

    def clean_village_covered(self, value):
        if not value:
            raise forms.ValidationError("Village covered must be set")
        return value
👤AKX

Leave a comment