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?
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.
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.
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 .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With