Django用户的自定义用户配置文件 [英] Custom User profile for Django user

查看:260
本文介绍了Django用户的自定义用户配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Django-模型扩展与用户个人资料

Django - Models extension Vs User Profile

我想添加一些自定义字段,例如以下

I want add some custom fields like following


 1. ssn 
 2. is_manager  
 3. manager

我有2个选择-
扩展AbstractBaseUser

基于信号创建用户个人资料,并具有OnetoOne字段。
哪一个更好,可以证明未来,数据库迁移友好且可维护?

I have 2 choices - Extend AbstractBaseUser OR Create User profile based on signal and have OnetoOne field. Which one is better, future proof, DB migration friendly and maintainable ?

推荐答案

Django文档详细回答此问题

The Django documentation answers this question in detail:


如果您想存储与 User 相关的信息,则可以使用 OneToOneField 到包含其他信息字段的模型。这种一对一模型通常称为配置文件模型,因为它可能存储有关站点用户的与身份验证无关的信息。

If you wish to store information related to User, you can use a OneToOneField to a model containing the fields for additional information. This one-to-one model is often called a profile model, as it might store non-auth related information about a site user.

在您的情况下,添加的字段似乎与身份验证无关,因此最好的选择是使用用户个人资料方法。出于这种目的,替换自定义用户模型是过大的。

In your case, the added fields do not seem to be authentication related, so your best bet is to use the user profile method. Substituting a custom user model is overkill for such purposes.

这篇关于Django用户的自定义用户配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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