-
Notifications
You must be signed in to change notification settings - Fork 208
Open
Description
There is a bug in Chapter05/bookmarks/account/forms.py (see this file) in the clean_email method. The code uses User.objects.filter(email=data).exists(), but User is not defined or imported in this file. This causes a NameError or import issues, especially if a custom user model is being used.
Current code (problematic):
def clean_email(self):
data = self.cleaned_data['email']
if User.objects.filter(email=data).exists():
raise forms.ValidationError('Email already in use.')
return data
How to fix:
Replace usage of User with get_user_model() as follows:
from django.contrib.auth import get_user_model
def clean_email(self):
data = self.cleaned_data['email']
User = get_user_model()
if User.objects.filter(email=data).exists():
raise forms.ValidationError('Email already in use.')
return data
Metadata
Metadata
Assignees
Labels
No labels