【发布时间】:2016-02-02 16:21:19
【问题描述】:
我正在使用 django 的身份验证来登录用户。但我有两个模型,authenticate 方法将检查用户凭据。一个是ApplicationUser,另一个是SystemUser,我已经制作了其中一个,效果很好:
models.py
class UserManager(BaseUserManager):
def create_user(self, email, password=None):
"""
Creates and saves a User with the given username and password.
"""
....
return user
def create_superuser(self, email, password):
...
return user
class ApplicationUser(AbstractBaseUser):
application_user_id = models.AutoField(primary_key=True)
....
....
views.py
def login_view(request):
...
user = authenticate(username = email, password = password)
if user is not None:
...
login(request, user)
....
....
我遇到了这个问题并得到了here,但我无法解决这个问题。
我的问题:
我如何指定两个
AUTH_USER_MODEL,到目前为止我已经设置ApplicationUser为AUTH_USER_MODEL。即使我以某种方式指定 两个
AUTH_USER_MODEL,authenticate或login功能如何 知道在哪里(ApplicationUser或SystemUser)匹配凭据并为用户创建会话 相应地
【问题讨论】:
标签: python django django-authentication