I have the code below:
===
class UserEmailForm(ModelForm):
    class Meta:
        model = User
        fields = ['email',]

    def clean_email(self):
        email_submitted = self.cleaned_data.get('email')
        email_exists =
User.objects.filter(email=email_submitted).exclude(username=request.user.username).count()

        if email_exists:
            raise forms.ValidationError('That email address is in
use')
        else:
            return email
===

And when I try to request the form with my browser I get the following
error:

===
NameError at /profile/update

global name 'request' is not defined

Request Method:         POST
Request URL:    http://mydomain.com/profile/update
Exception Type:         NameError
Exception Value:

global name 'request' is not defined

Exception Location:     /var/virtualhosts/twiturl_com/redirect/forms.py
in clean_email, line 18
===

How do I access request.user in the clean_email method of the
UserEmailForm ModelForm?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to