Package: django-custom-user
Custom user model for Django with the same behaviour as the default User class but without a username field. Uses email as the USERNAME_FIELD for authentication.Quick startInstall django-custom-user with your favorite Python package manager:pip install django-custom-userAdd'custom_user'to yourINSTALLED_APPSsetting:INSTALLED_APPS=(# other apps'custom_user',)Set yourAUTH_USER_MODELsetting to useEmailUser:AUTH_USER_MODEL='custom_user.EmailUser'Create the database tables:python manage.py migrateUsageInstead of referring toEmailUserdirectly, you should reference the user model usingget_user_model()as explained in theDjango documentation. For example:fromdjango.contrib.authimportget_user_modeluser=get_user_model().objects.get(email="user@example.com")When you define a foreign key or many-to-many relations to theEmailUsermodel, you should specify the custom model using theAUTH_USER_MODELsetting. For example:fromdjango.confimportsettingsfromdjango.dbimportmodelsclassArticle(models.Model):author=models.ForeignKey(settings.AUTH_USER_MODEL)Extending EmailUser modelYou can easily extendEmailUserby inheriting fromAbstractEmailUser. For example:fromcustom_user.modelsimportAbstractEmailUserclassMyCustomEmailUser(AbstractEmailUser):"""
    Example of an EmailUser with a new field date_of_birth
    """date_of_birth=models.DateField()Remember to change theAUTH_USER_MODELsetting to your new class:AUTH_USER_MODEL='my_app.MyCustomEmailUser'If you use the AdminSite, add the following code to yourmy_app/admin.pyfile:fromdjango.contribimportadminfromcustom_user.adminimportEmailUserAdminfrom.modelsimportMyCustomEmailUserclassMyCustomEmailUserAdmin(EmailUserAdmin):"""
    You can customize the interface of your model here.
    """pass# Register your models here.admin.site.register(MyCustomEmailUser,MyCustomEmailUserAdmin)Supported versionsDjango:3.2 LTS4.0Python:3.73.83.93.10ChangelogVersion 1.1 (2022-12-10)Added support for Django 4.1 and Python 3.11.Version 1.0 (2022-03-29)After a long hiatus, this new version brings compatibility with the latest Django and Python versions, among lots of small improvements and cleanups.Supported versions:Django: 3.2 LTS, 4.0Python: 3.7, 3.8, 3.9, 3.10Import latest code changes from Django 4.0 (#65):EmailUserCreationFormdoes not strip whitespaces in the password fields, to match Django’s behavior.EmailUserCreationFormsupports custom password validators configured byAUTH_PASSWORD_VALIDATORS.EmailUser.objects.create_superuser()allows empty passwords. It will also check that bothis_staffandis_superuserparameters areTrue(if passed). Otherwise, it would create an invalid superuser.Internal changes:Moved away from Travis CI to Github Actions.Build system and dependencies managed withPoetry.Code formatted withblackandisort.Note that older versions of Django are not supported, but you can use the previous version 0.7 if you need it.Version 0.7 (2017-01-12)Fixed change password link in EmailUserChangeForm (thanks to Igor Gai and rubengrill)Version 0.6 (2016-04-03)Added migrations (thanks to everybody for the help).How to apply the migrations after upgrading:Django 1.7For this version just run the following commands.python manage.py migrate custom_user 0001_initial_django17 --fake
python manage.py migrate custom_userDjango 1.8This 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’sMIGRATION_MODULESsetting, delete the folder containing the migration modules and remove the setting from your config.If you just ranpython manage.py makemigrations, the migrations are located inside your system’s or virtualenv’ssite-packagesfolder. You can check the location running this command, and then delete the foldermigrationsthat 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 sectioncustom_useranymore:python manage.py migrate --listOnce the old migrations are gone, run the following command to finish:python manage.py migrate custom_user 0002_initial_django18 --fakeVersion 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.