Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove username field in the register form on django admin?

using the rest-framework and the django-allauth settings flags for removing the username as required for both login and register:

#settings.py
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USERNAME_REQUIRED = False

but i still see the username field in the registration form in the administrator and the username field in the user list (empty users those without username).

how can i remove it?

like image 393
Francisco Henseleit Avatar asked Mar 18 '16 21:03

Francisco Henseleit


People also ask

How can I change user field in Django?

As we all know the default User model in django uses a username to uniquely identify a user during authentication. If you need to replace this username field with other field lets say an email field then you need to create a custom user model by either subclassing AbstractUser or AbstractBaseUser.

How do I make my Django username not unique?

If you want to use django's default authentication backend you cannot make username non unique. You will have to implement a class with get_user(user_id) and authenticate(request, **credentials) methods for a custom backend.

What is username field in Django?

For Django's default user model, the user identifier is the username, for custom user models it is the field specified by USERNAME_FIELD (see Customizing Users and authentication). It also handles the default permissions model as defined for User and PermissionsMixin .


1 Answers

Essentially this involves creating a custom user model and informing Django and Django Admin portions that it should be used instead of the standard model.

Your class will look like the following.

class User(AbstractUser):
    username = None
    email = models.EmailField(_('email address'), unique=True)
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

The details of the implementation can be found here

like image 101
Maulik Harkhani Avatar answered Oct 04 '22 01:10

Maulik Harkhani