Implementing multiple user types with Django 1.5

后端 未结 4 1507
挽巷
挽巷 2020-12-07 11:25

What is the recommended way to implement multiple user types using Django 1.5\'s new configurable user model functionality?

I would like to have two user types: priv

4条回答
  •  忘掉有多难
    2020-12-07 12:26

    The new custom user model you can assign only one model to AUTH_USER_MODEL. With multi-table inheritance you have two models. So that is a problem.

    In the case of a single user model that covers both user types you could abstract the conditional logic in the model methods. You can also use different managers for different user types based on how much they are different. This could also help you in being explicit when working with a specific user type.

    Other option could be to store only most common attributes in a single user model and then attach specifics of two user types into their own tables which are linked to your main user table.

    If both users have most of the things in common (in terms of data at least), I would keep them in one place. In the end, I would think about what is simpler and easier to maintain.

提交回复
热议问题