Django - replace username as primary key with email
Django is a great tool, but nothing in this world is perfect.
Having a username could be fancy in the early web, but today, with tons of site and consequently credentials, people tend to simplify things to remember (at least, I do).
Generally, when I start a Django project I immediately create a Customer User Model (it's a Django best practice).
But the process is a bit tedious, because you have to:
- Extend the Django User class
- Modify settings.py to use the new user model
- Configure the managers (or they will broke when you create user from cli)
- Modify the admin view
You can skip to the official documentation and copy and paste based on your needs
Here are some useful links that helps me in this process:
- https://www.fomfus.com/articles/how-to-use-email-as-username-for-django-authentication-removing-the-username/
- https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model
- https://docs.djangoproject.com/en/dev/topics/auth/customizing/#substituting-a-custom-user-model
- A full example
Top comments (0)