Package: django-username-email-fullname
CUser makes it easy to use email address as your identification token
instead of a username.CUser is a custom Django user model (extendsAbstractBaseUser) so it
takes a tiny amount of effort to use.The only difference between CUser and the vanilla DjangoUseris email
address is theUSERNAME_FIELD(and username does not exist).CUser supports Django 1.8+Why use CUser?Because you want everything indjango.contrib.authexcept for theusernamefield and you also want users tolog in with email addresses.
And you don’t want to create your own custom user model or authentication
backend.Install & Set upIf you previously used Django’s default user model,django.contrib.auth.models.User, jump toNotesfirst (then come
back). Otherwise, continue onward!Install withpip installdjango-username-email-fullnameAddcuserto yourINSTALLED_APPSsetting:INSTALLED_APPS=[...'cuser',]Specify the custom model as the default user model for your project
using theAUTH_USER_MODELsetting in your settings.py:AUTH_USER_MODEL='cuser.CUser'Instead of referring to User directly, you should reference the user
model usingdjango.contrib.auth.get_user_model()If you use Django’s defaultAuthenticationFormclass, it is
strongly recommended that you replace it with the one included with
CUser. This will make the<input>have itstypeattribute set
toemailand browsers’ autocomplete feature will suggest email
addresses instead of usernames. For example, if your project is using
Django’s defaultloginview, this is what you would put in your
urls.py in order to make use of CUser’sAuthenticationFormclass:fromcuser.formsimportAuthenticationFormfromdjango.conf.urlsimportinclude,urlfromdjango.contrib.auth.viewsimportloginurlpatterns=[url(r'^accounts/login/$',login,{'authentication_form':AuthenticationForm},name='login'),url(r'^accounts/',include('django.contrib.auth.urls')),...]Run migrations.pythonmanage.pymigrateConfigurationTo override any of the default settings, create a dictionary namedCUSERin
your settings.py with each setting you want to override. For example:CUSER={'app_verbose_name':'Authentication and Authorization','register_proxy_auth_group_model':True,}These are the settings:app_verbose_name(default:_("CustomUser"))This controls the value that CUser will use for itsAppConfigclass’verbose_name.register_proxy_auth_group_model(default:False)When set toTrue, CUser’s admin.py will unregister Django’s defaultGroupmodel and register its own proxy model of Django’s defaultGroupmodel (also namedGroup). This is useful if you want Django’s defaultGroupmodel to appear in the same part of the admin as CUser’sCUsermodel.NotesIf you have tables referencing Django’sUsermodel, you will have to
delete those table and migrations, then re-migrate. This will ensure
everything is set up correctly from the beginning.When you define a foreign key or many-to-many relations to theUsermodel, you should specify the custom model using theAUTH_USER_MODELsetting.For example:fromdjango.confimportsettingsfromdjango.dbimportmodelsclassProfile(models.Model):user=models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE,)LicenseReleased under the MIT license. See LICENSE for details.Questions, comments, or anything else?Open an issueTwittertom@meagher.co