Django Multi-Table Inheritance VS Specifying Explicit OneToOne Relationship in Models

后端 未结 5 2109
萌比男神i
萌比男神i 2021-01-30 11:53

Hope all this makes sense :) I\'ll clarify via comments if necessary. Also, I am experimenting using bold text in this question, and will edit it out if I (or you) find it distr

5条回答
  •  粉色の甜心
    2021-01-30 12:42

    Do you need objects of your user classes to act like an auth.User anywhere? That would be the most obvious reason to use inheritance over OneToOne. One pro of the OneToOne approach would be the ease in which you can change over to another User model, if that's a concern.

    The real issue I see with what you have above (by either method) is that there doesn't appear to be anything stopping you from having a Principal object and an Administrator object share the same User. OneToOneField can only guarantee a one-to-one mapping between any two relations.

提交回复
热议问题