简体   繁体   English

想要通过添加两个字段来扩展Django中的auth_user模型

[英]want to extend auth_user model in django by adding two fields

in django,i want to extend the auth_user model and adding the 2 fields.one is created_user which will display the date and time when user created something and other is modified_user which will display the date n time when modification is done.. 在django中,我想扩展auth_user模型并添加2个字段。一个是created_user,它将在用户创建内容时显示日期和时间,另一个是Modifyed_user,将在完成修改后显示日期n。

is it possible by migration?? 迁移有可能吗? i ve tried dis code.. 我试过dis代码。

from django.contrib.auth.models import User, UserManager

class CustomUser(User):
    created_user= models.DateTimeField("date and time when created")
    modified_user=models.DateTimeField("date and time when modified")

    objects= UserManager()

I suggest reading the documentation on creating your own custom user model. 我建议阅读有关创建自己的自定义用户模型的文档

In your particular case, the easiest thing would probably be to subclass AbstractUser and add your fields as above. 在您的特定情况下,最简单的方法可能是继承AbstractUser并添加上述字段。

If you're entirely happy with Django's User model and you just want to add some additional profile information, you can simply subclass django.contrib.auth.models.AbstractUser and add your custom profile fields. 如果您对Django的用户模型完全满意,并且只想添加一些其他配置文件信息,则可以简单地将django.contrib.auth.models.AbstractUser子类化并添加自定义配置文件字段。 This class provides the full implementation of the default User as an abstract model. 此类提供默认用户的完整实现,作为抽象模型。

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

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