简体   繁体   中英

Should i use proxy models in django?

im here trying to start a new project, in django and i came across this problem, while creating the models My users will be different types of users, so i was thinking, should i use proxy models for it? because here is how it´s going to be the realtionship between them. i will have a client, and a personal trainer, and the admin of course, but the problem here is that the client is going to have a ForeignKey with personal trainer, my main question is, can i create in a proxy model an extra field where i establish the relationship with personal trainer proxy model?

If not, is there any other way that i can aproach this type of situation

Thanks in advance

No. As far as I know a Proxy Model only changes the behavior of a model. You can add new methods only. If you want to add new fields it must be a Concrete Model.

You should create a new model class which inherits from AbstractUser . Then you can either add a type field which can be "client" or "personal_trainer" or "whatever". Or you could use a OneToOne field to have a UserProfile associated w/ your user - a different profile for "clients" or "personal_trainers" or "whatevers".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM