简体   繁体   English

如何更新Standart Django模型(auth_user)

[英]How to update standart Django model (auth_user)

I would like to add new field into existing model (in this case - User(auth_user)). 我想将新字段添加到现有模型中(在这种情况下-User(auth_user))。 For example, there are fields "first_name", "last_name", "email".. etc. Please advise how best to implement this? 例如,有字段“ first_name”,“ last_name”,“ email” ..等。请告知如何最好地实现此目的?

You can extend or create you own substitute User model. 您可以扩展或创建自己的替代用户模型。 In my point of view is better to create your own. 在我看来,最好创建自己的。

from django.db import models
from django.contrib.auth.models import AbstractUser

class User(AbstractUser):
    my_field = models.CharField(max_length = 150)

and then in your settings.py 然后在您的settings.py中

AUTH_USER_MODEL = 'myapp.User'

I hope this help you. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM