Skip to content

Instantly share code, notes, and snippets.

@bmispelon
Created November 24, 2012 08:01
Show Gist options
  • Select an option

  • Save bmispelon/4138833 to your computer and use it in GitHub Desktop.

Select an option

Save bmispelon/4138833 to your computer and use it in GitHub Desktop.
UserCreationForm issues with custom user model
from django.contrib.auth.forms import UserCreationForm
class SignupForm(UserCreationForm):
pass
>>> from myapp.forms import SignupForm
>>> f = SignupForm({'username': 'foo', 'password1': 'bar', 'password2': 'bar'})
>>> f.is_valid()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/path/to/my/venv/lib/python2.7/site-packages/django/forms/forms.py", line 126, in is_valid
return self.is_bound and not bool(self.errors)
File "/path/to/my/venv/lib/python2.7/site-packages/django/forms/forms.py", line 117, in _get_errors
self.full_clean()
File "/path/to/my/venv/lib/python2.7/site-packages/django/forms/forms.py", line 272, in full_clean
self._clean_fields()
File "/path/to/my/venv/lib/python2.7/site-packages/django/forms/forms.py", line 290, in _clean_fields
value = getattr(self, 'clean_%s' % name)()
File "/path/to/my/venv/lib/python2.7/site-packages/django/contrib/auth/forms.py", line 87, in clean_username
User.objects.get(username=username)
File "/path/to/my/venv/lib/python2.7/site-packages/django/db/models/manager.py", line 256, in __get__
self.model._meta.object_name, self.model._meta.swapped
AttributeError: Manager isn't available; User has been swapped for 'myapp.User'
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
pass
AUTH_USER_MODEL = 'myapp.User'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment