Same username and email for django user?

1.3k views Asked by At

I'm making a django website using the django-registration package. I'd like for users to register with their emails and have no username so that i can then have an interface with their actual names (like on facebook) and keep track of them through their email.

I will need a user profile and plan to extend the user model with a oneToOne field later on but for now I'm not sure how to use their email as username. I figured i could simply ask the user for their email and also store it as a username and that would be a simple fix. However it will require me modifying all the forms and will create essentially duplicate column in the database (email = username).

This question is really open ended, I'd like to know if there's an easy way of changing the user model mid project. I've read the docs about the User(AbstractUser) class but that seems to be good only if we just started the project.

Thanks, any help will be appreciated.

1

There are 1 answers

2
Darshit On

You can write custom user class by extending AbstractBaseUser, and declare your email field as USERNAME_FIELD like:

USERNAME_FIELD = 'email'

Another work around without extending AbstractBaseUser can be import User model in your apps.py and set USERNAME_FIELD like:

from django.contrib.auth.models import User
User.USERNAME_FIELD = 'email'