Can I change the USERNAME_FIELD in Django 1.5 without creating a custom user?

前端 未结 2 905
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-04 20:08

I am trying to use the email field in the default Django user model as the username. I am using Django 1.5 and I saw that the default user has a USERNAME_FIELD

相关标签:
2条回答
  • 2021-01-04 20:33

    You have to write a new Custom User Class by extending the AbstractBaseUser and not AbstractUser

    Declare your email as the USERNAME_FIELD there

    Optionally you can also declare a custom user manager that extends from BaseUserManager to handle the username required constraint. You can remove username from that manager's create_user function

    0 讨论(0)
  • 2021-01-04 20:34
    #Your app's __init__.py
    
    from django.contrib.auth.models import User
    
    User.USERNAME_FIELD = 'email'
    
    0 讨论(0)
提交回复
热议问题