Custom user model for Django >= 1.5 with the same behaviour as Django's default User but with email instead of username.
Project description
Custom user model for Django >= 1.5 with the same behaviour as Django’s default User but without a username field. Uses email as the USERNAME_FIELD for authentication.
Quick start
Install django-custom-user with your favorite Python package manager:
pip install django-custom-user
Add 'custom_user' to your INSTALLED_APPS setting:
INSTALLED_APPS = (
# other apps
'custom_user',
)
Set your AUTH_USER_MODEL setting to use EmailUser:
AUTH_USER_MODEL = 'custom_user.EmailUser'
Create the database tables.
python manage.py syncdb
Usage
Instead of referring to EmailUser directly, you should reference the user model using get_user_model() as explained in the Django documentation. For example:
from django.contrib.auth import get_user_model
user = get_user_model().get(email="user@example.com")
When you define a foreign key or many-to-many relations to the EmailUser model, you should specify the custom model using the AUTH_USER_MODEL setting. For example:
from django.conf import settings
from django.db import models
class Article(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL)
Extending EmailUser model
You can easily extend EmailUser by inheriting from AbstractEmailUser. For example:
from custom_user.models import AbstractEmailUser
class MyCustomEmailUser(AbstractEmailUser):
"""
Example of an EmailUser with a new field date_of_birth
"""
date_of_birth = models.DateField()
Remember to change the AUTH_USER_MODEL setting to your new class:
AUTH_USER_MODEL = 'my_app.MyCustomEmailUser'
If you use the AdminSite, add the following code to your my_app/admin.py file:
from django.contrib import admin
from custom_user.admin import EmailUserAdmin
from .models import MyCustomEmailUser
class MyCustomEmailUserAdmin(EmailUserAdmin):
"""
You can customize the interface of your model here.
"""
pass
# Register your models here.
admin.site.register(MyCustomEmailUser, MyCustomEmailUserAdmin)
Changelog
Version 0.5 (2014-09-20)
Django 1.7 compatible (thanks to j0hnsmith).
Custom application verbose_name in AdminSite with AppConfig.
Version 0.4 (2014-03-06)
The create_user() and create_superuser() manager methods now accept is_active and is_staff as parameters (thanks to Edil Kratskih).
Version 0.3 (2014-01-17)
AdminSite now works when subclassing AbstractEmailUser (thanks to Ivan Virabyan).
Updated model changes from Django 1.6.1.
Version 0.2 (2013-11-24)
Django 1.6 compatible (thanks to Simon Luijk).
Version 0.1 (2013-04-09)
Initial release.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_custom_user-0.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b3f3b9245aa0f480a9177a62dace35129ff442a0d67a3ac529b3a3ae1642276 |
|
MD5 | ab8bc41d1ab690eb3faf91a52af9d642 |
|
BLAKE2b-256 | 87ab7e73df9355f6da94dc2338cd75926812c94c8be0030dfe29a44492f26f1d |