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

前端 未结 3 417
孤街浪徒
孤街浪徒 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

    What is the best way to structure this so that I can have two different types of users with different fields, without causing me any problems in user authentication, user creation, or the admin?

    You actually only have one type of user. Just that some users have specific properties set and others do not. Consider how django has "users" and "admins". They are the instances of the same model, but with different properties and permissions.

    You should approach it similarly. Have one user model for your entire application. You can set properties/methods in your custom user class to identify what flags this user has set (which would determine the "type" of user there is).

    Also, how will I be able to tell from login alone whether this user is a CustomerUser or a StoreOwnerUser?

    You can use the user_passes_test decorator, which takes an argument that is a function name and will only process the view if the function returns a truth value.

提交回复
热议问题