Is it possible to get request.user data in a form class? I want to clean an email address to make sure that it's unique, but if it's the current users email address then it should pass.
This is what I currently have which works great for creating new users, but if I want to edit a user I run into the problem of their email not validating, because it comes up as being taken already. If I could check that it's their email using request.user.email then I would be able to solve my problem, but I'm not sure how to do that.
class editUserForm(forms.Form):
email_address = forms.EmailField(widget=forms.TextInput(attrs={'class':'required'}))
def clean_email_address(self):
this_email = self.cleaned_data['email_address']
test = UserProfiles.objects.filter(email = this_email)
if len(test)>0:
raise ValidationError("A user with that email already exists.")
else:
return this_email