1
我正在使用django的身份驗證登錄用戶。但我有兩個模型從authenticate
方法將檢查用戶憑據。一個是ApplicationUser
,另一個是SystemUser
我做了其中的一個,它工作正常,像這樣:如何在Django身份驗證中配置兩個AUTH_USER_MODEL
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
)相匹配的憑證和用戶 相應
我已經做了,與'ApplicationUser'這是我CustomUserModel。我怎樣才能爲'SystemUser'指定呢? – Sibtain
@Sibtain你可以只有一個認證模型,如果你想要從你的主要UserModel派生的其他模型,你需要擴展你的AUTH USER MODEL。 – levi
你能舉一個粗略的例子嗎? – Sibtain