CustomUserModel

For creating a custom user model define in the global configuration the app and name of it::

# settings.py
...
AUTH_USER_MODEL = 'myapp.CustomUser'
...

Extend the AbstractUser class when it is intended to keep most of the original User model features::

# models.py
...
class CustomUser(AbstractUser):
    custom_field = models.ForeignKey('OtherModel')
    objects = UserManager()

...

In the admin the normal User model needs to be unregistered, while the custom one needs to be registered:

# admin.py
...
admin.site.unregister(User)
admin.site.register(CustomUser)
...

[http://stackoverflow.com/questions/13568172/django-1-5-custom-user-model-error-manager-isnt-available-user-has-been-swap/13593323#13593323]


Tags: authentication django django,

Edit this page
Wiki-logo