13👍
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
2👍
You need to define your own custom user model to remove it from Django admin. If you can live with Django’s user model with the username, but want it removed from serializers (DRF), you could define your own custom login and register serializers and remove username there.
- Django rest framework offline documentation
- Django-rest-framework HyperlinkedIdentityField with multiple lookup args
1👍
In your settings.py
file:
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
https://django-allauth.readthedocs.io/en/latest/advanced.html#custom-user-models
- Django RuntimeError at /admin/users/user/1/change/, Single thread executor already being used, would deadlock
- How to set default values in TabularInline formset in Django admin
- Celery immediately exceeds memory on Heroku
- How to logout in django?
- Drawing graphs in Django
0👍
You can also override the base admin template as described in the SO answers here:
How to override and extend basic Django admin templates?
- Adding static() to urlpatterns only work by appending to the list
- Passing a variable in redirect in Django
- Query a template for the variables it needs?
0👍
In my case, I simply put ‘username = None’ there. Then it’s gone.
Full code:
from django.utils.translation import gettext_lazy as _
class LectureUser(AbstractUser):
username = None
identifier = models.IntegerField(primary_key=True)
email = models.EmailField(_('email address'))
USERNAME_FIELD = 'identifier' # Set to the unique identifier we define.
objects = CustomUserManager()
Hope this helps 🙂