如何在Django中使用多个用户模型? [英] How to use multiple user models in Django?

查看:91
本文介绍了如何在Django中使用多个用户模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用两个用户模型,每个用户模型具有不同的用户名"类型.

第一个用户类型是使用用户名和密码登录的管理员.其次,使用电话号码和密码登录的客户.只有客户具有自定义字段.

我尝试自定义Django用户模型,但它仅允许一个身份验证用户模型.

我正在考虑使用身份验证后端.

仅管理员将登录管理控制台,而客户仅将登录应用程序.

编辑.

来自不同的问题.我的用户类型具有不同的登录方式.

我的解决方案:仅将Django的用户模型用于仪表板管理员.将客户模型与自定义身份验证后端一起使用.

解决方案

第一个用户类型是使用用户名和密码登录的管理员.其次,使用电话号码和密码登录的客户.只有客户具有自定义字段.

您不希望有多个用户模型(疯狂,而且Django并没有真正支持该模型).您需要多个身份验证后端./p>

使用(可空的)电话号码字段输入用户模型.并在您的应用程序中添加使用电话号码+密码而不是用户名+密码的auth后端.

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.

解决方案

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.

这篇关于如何在Django中使用多个用户模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆