How can I access request.user in a clean method of a ModelForm?
I have the following code in forms.py:
===
#profle email form
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
===
When I attempt to pull up the form, I get this error:
===
NameError at /profile/update
global name 'request' is not defined
Request Method: POST
Request URL: http://dev.twiturl.com/profile/update
Exception Type: NameError
Exception Value:
global name 'request' is not defined
===
Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---