我使用django的身份验证来登录用户。但是我有两个模型,其中authenticate
方法将检查用户凭证。一个是ApplicationUser
,另一个是SystemUser
我做了一个,效果很好:
模型.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)
....
....
视图.py
^{pr2}$我解决了这个问题,得到了here,但我无法想出解决办法。在
我的问题:
我如何指定两个AUTH_USER_MODEL
,到目前为止我已经设置好了
ApplicationUser
作为AUTH_USER_MODEL
。
即使我指明
这两个AUTH_USER_MODEL
,authenticate
或{ApplicationUser
或SystemUser
)匹配凭据并为用户创建会话
相应地
在你的设置.py设置
剩下的就交给django吧。在
如果您想要其他用户模型,您需要从您选择的
AUTH_USER_MODEL
扩展它们相关问题 更多 >
编程相关推荐