AbstractUser属性与UserProfile模型 [英] AbstractUser attributes vs UserProfile Model

查看:49
本文介绍了AbstractUser属性与UserProfile模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于为用户设计模型的问题.如果您这样做是更好的方法吗?创建一个AbstractUser模型,并将所有其他属性(例如:电话,手机,传真)放入模型中 vss 创建一个名为UserProfile的单独模型,并使用OneToOneField将其与Member链接起来?

I have a question regarding designing models for the User. Is it a better approach if you : create an AbstractUser model and put all extra attributes (eg: phone, mobile, fax) inside the model v.s creating a separate model called UserProfile and link it up with the Member using OneToOneField ?

推荐答案

答案在

如果您对Django的用户模型完全满意,并且只想添加一些其他配置文件信息,您可以简单地子类化django.contrib.auth.models.AbstractUser并添加您的自定义配置文件字段中,尽管我们建议使用单独的模型,如指定自定义用户模型的模型设计注意事项"注释.AbstractUser提供默认用户的完整实现,具体为抽象模型.

If you’re entirely happy with Django’s User model and you just want to add some additional profile information, you could simply subclass django.contrib.auth.models.AbstractUser and add your custom profile fields, although we’d recommend a separate model as described in the "Model design considerations" note of Specifying a custom User model. AbstractUser provides the full implementation of the default User as an abstract model.

这篇关于AbstractUser属性与UserProfile模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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