[Answer]-Modelform ignoring required=True

1👍

try this:

def clean(self):
    cleaned_data = super(DjangoUserForm, self).clean()
    if not self._errors:
        email = self.cleaned_data['email']
        username = self.cleaned_data['username']

        if not User.objects.exclude(username=username).filter(email=email).exists():
            return cleaned_data
        else:    
            from django.forms.util import ErrorList
            self._errors['email'] = ErrorList()
            self._errors['email'].append('Email is used by another user')

Leave a comment