1.引入AbstractUser from django.contrib.auth.models import AbstractUser 2.# 继承并重写user class User(AbstractUser): #删除字段 这里是不想要的字段,直接赋值为None即可 first_name = None last_name = None groups = None user_permissions = None #添加字段 Role = models.ForeignKey('account.Role', on_delete=models.CASCADE, null=True) nickname = models.CharField(max_length=30, null=True, blank=True, verbose_name="姓名") mobile = models.CharField(null=True, blank=True, max_length=11, verbose_name="电话") creator = models.CharField('创建人', max_length=200,null=True) modifier = models.CharField('修改人', max_length=200, null=True ) create_time = models.DateTimeField('创建时间',auto_now=datetime.datetime.now(), null=True) modify_time = models.DateTimeField('修改时间',auto_now=datetime.datetime.now(),null=True ) class Meta: verbose_name_plural = '账号' verbose_name = '账号' unique_together = (("mobile"),) def __str__(self): return self.username 3.在settings.py中添加 AUTH_USER_MODEL = 'account.User' 4.在admin.py中注册
class UserInfoAdmin(admin.ModelAdmin): list_display = ('username','email')
admin.site.register(User, UserInfoAdmin)