django custom form clean() raising error from clean_field()
<p>I have created a custom form and need to override both of the <code>clean_field()</code> method and <code>clean()</code> method. Here is my code:</p>

<pre><code>class MyForm(forms.Form):
    username=forms.RegexField(regex=r'^1[34578]\d{9}$')
    code = forms.RegexField(regex=r'^\d{4}$')

    def clean_username(self):
        u = User.objects.filter(username=username)
        if u:
            raise forms.ValidationError('username already exist')
        return username

    def clean(self):
        cleaned_data = super(MyForm, self).clean()
        # How can I raise the field error here?
</code></pre>

<p>If I save this form twice, and the username will be already exist in the second time, the <code>clean_username</code> method will raise an error, however, the <code>clean()</code> method still run without interruption. </p>

<p>So my question is, how can I stop calling <code>clean()</code> when error already raise by <code>cleaned_xxx</code>, if that is not possible, then how can I raised the error again which raised by <code>clean_xxxx()</code> in <code>clean()</code> method?</p>

<p>In your <code>clean</code> method, you can check whether <code>username</code> is in the <code>cleaned_data</code> dictionary.</p>

<pre><code>def clean(self):
    cleaned_data = super(MyForm, self).clean()
    if 'username' in cleaned_data:
        # username was valid, safe to continue
        ...
    else:
        # raise an exception if you really want to
</code></pre>

<p>You probably don't need the else statement. The user will see the error from the <code>clean_username</code> method so you don't need to create another one.</p>

python django forms validation