I'm using django's authentication to login users. But I have two models from where authenticate
method would check the user credentials. One is ApplicationUser
and the other is SystemUser
I have made one of them and it works fine like so:
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)
....
....
I came through this problem and got here but I couldn't work out a solution to this.
My Questions:
How do I specify two
AUTH_USER_MODEL
, as of yet I have setApplicationUser
asAUTH_USER_MODEL
.And even if I somehow specify the two
AUTH_USER_MODEL
, how do theauthenticate
orlogin
function know where (ApplicationUser
orSystemUser
) to match the credentials and create session for the user accordingly