1.在Django中的models.py建表
from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.
class UserInfo(AbstractUser):
nid = models.AutoField(primary_key=True)
phone = models.CharField(max_length=11, null=True)
avatar = models.FileField(upload_to="avatars/", default="avatar/default.png", verbose_name="头像")
create_time = models.DateTimeField(auto_now_add=True)
blog = models.OneToOneField(to="Blog", to_field="nid", null=True)
def __str__(self):
return self.username
class Blog(models.Model):
"""
博客信息
"""
nid = models.AutoField(primary_key=True)
title = models.CharField(max_length=64) # 个人博客标题
site = models.CharField(max_length=32, unique=True) # 个人博客后缀
theme = models.CharField(max_length=32) # 博客主题
def __str__(self):
return self.title
2.在settings.py中
# 告诉Django项目用哪个APP下的哪儿张表做认证
AUTH_USER_MODEL = 'APP名称.UserInfo'