Setting up two different types of Users in Django 1.5/1.6

前端 未结 3 412
孤街浪徒
孤街浪徒 2021-01-30 09:51

Please note--this is an updated version of my original question on this subject, but deserves to be asked again with the change in how Django deals with users and authentica

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-30 10:15

    It seems like there are some common features and uncommon features to your user types. If there are common features in your user types that Django's default User model doesn't support out of the box, you should subclass it directly.

    Adding in extra, uncommon features to your user types are best done not by subclassing but by using a profile. My rationale for this is because your authentication for these user types doesn't fundamentally change, but details about the user does depending on the type of user it is. To accomodate this, you create a separate model with these details and reference your User class as a OneToOne/ForeignKey relationship (depending on your design).

    You can make modifications to your user creation process to identify what kind of user type it should be, and set its associated OneToOneField/ForeignKey (depending on your design) to the appropriate customer type model.

    By doing it this way, you should only have one AUTH_USER_MODEL, and you should be able to handle details for your different customer types.

提交回复
热议问题