'How to have multiple Auth models in django
I have an application where I've two models both models have same fields
- client
- buyer
I'm using separate models because client can also signs up as a buyer using the same email and vice versa. I don't want to use single model for both client and buyer with some checks like is_buyer/is_client. How do I achieve something like
class Client(AbstractUser):
email = Field()
password = Field()
class Buyer(AbstractUser):
email = Field()
password = Field()
AUTH_USER_MODEL=app.Client
AUTH_USER_MODEL=app.Buyer
Also I'm using simpleJWT library, so I can generate jwt when the client or buyer logins in.
Solution 1:[1]
You can use the User model and add a new field(Type) with two choices (client-buyer) and create two models (Client/Buyer) both of them OneToOne with the User model
when the user register, he will insert his type or you should find a way to know his type then in the User model save his type then save the other data in the next model (Client/Buyer) depending on the type
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | K.D |