[Django]-Require that some fields can't left all blank. at least one is required

2👍

You can’t enforce it on the database level, but you can do this in model validation:

def clean(self):
    if not self.file1 and not self.file2 and not self.file3:
        error_msg = 'At least one of these fields must not be empty'
        raise ValidationError({
            'file1': error_msg,
            'file2': error_msg,
            'file3': error_msg,
        })

Leave a comment