How to use multiple user models in Django?

核能气质少年 提交于 2021-02-08 01:51:57

问题


I'm trying to use two user models with different 'username' type each one.

First user type is an administrator who login in with username and password. Second, a customer who login with phone number and password. Only the customer has custom fields.

I tried customize the Django User model but it only allows one auth user model.

I am thinking use an authentication backend.

Administrator only will login in admin dashboard, while customer only login in application.

Edit.

Different problem from. My user types have different ways to login each other.

My solution: Use Django's user model for dashboard administrator only. Use a Customer model with custom authentication backend.


回答1:


First user type is an administrator who login in with username and password. Second, a customer who login with phone number and password. Only the customer has custom fields.

You don't want multiple user models (crazy and not really supported in Django anyway). You want multiple authentication backends.

Put a User model with a (nullable) phone number field. And add to your application an auth backend which uses phone number + password instead of username + password.



来源:https://stackoverflow.com/questions/55582710/how-to-use-multiple-user-models-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!