Custom user model for Django >= 1.5 with the same behaviour as Django's default User but with email instead of username.
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.
pip install django-custom-user
INSTALLED_APPS = ( # other apps 'custom_user', )
AUTH_USER_MODEL = 'custom_user.EmailUser'
python manage.py migrate
Or if you are using an old Django version (<=1.6):
python manage.py syncdb
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().objects.get(email="firstname.lastname@example.org")
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)
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)
How to apply the migrations after upgrading:
For this version just run the following commands.
python manage.py migrate custom_user 0001_initial_django17 --fake python manage.py migrate custom_user
This version didn’t work without migrations, which means that your migrations will conflict with the new ones included in this version.
If you added the migrations with Django’s MIGRATION_MODULES setting, delete the folder containing the migration modules and remove the setting from your config.
If you just ran python manage.py makemigrations, the migrations are located inside your system’s or virtualenv’s site-packages folder. You can check the location running this command, and then delete the folder migrations that is inside:
python -c "import os; import custom_user; print(os.path.dirname(custom_user.__file__))"
You can check if you have removed the migrations successfully running this command, you shouldn’t see the section custom_user anymore:
python manage.py migrate --list
Once the old migrations are gone, run the following command to finish:
python manage.py migrate custom_user 0002_initial_django18 --fake
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|django_custom_user-0.7-py2.py3-none-any.whl (17.3 kB) Copy SHA256 Checksum SHA256||py2.py3||Wheel||Jan 12, 2017|
|django-custom-user-0.7.tar.gz (12.6 kB) Copy SHA256 Checksum SHA256||–||Source||Jan 12, 2017|