Created
March 29, 2016 07:28
-
-
Save josefmonje/8dab348d563678155f65 to your computer and use it in GitHub Desktop.
Django UserCreationForm - check if user exists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clean_username(self): | |
username = self.cleaned_data["username"] | |
try: | |
User.objects.get(username=username) | |
except User.DoesNotExist: | |
return username | |
raise forms.ValidationError(_("A user with that username already exists.")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks !