I am building a system where many accounts will not have login credentials (e.g companies) unless specifically provided. In order to achieve this, I have the following account model (not implemented yet, currently designing on a piece of paper):
Table: Account
Fields: ID, fname, lname, type, created_at, activated_at
Table: AccountCredentials
Fields: Account ID, email, password
Relations:
Account <- 1-to-1 -> AccountCredentials
All permissions, operations etc will be performed over the Account model; so, the Account model will be the django auth user model.
I have used custom User models and managers before; however, this is something I am not sure how to implement.
How should I tell the AbstractBaseUser model to authenticate using credentials.email
and credentials.password
(credentials
being the relation name between Account and AccountCredentials)? From checking AbstractBaseUser source code and checking some files, it seems like I can override get_username
method; so that, the username field is being read from credentials. However, I am not sure how to do the same for password as it is hard coded in model.