当前位置:   article > 正文

from django.contrib.auth.models import AbstractUser 的继承

from django.contrib.auth.models import abstractuser

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'

转载于:https://www.cnblogs.com/Guishuzhe/p/9569978.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/306477
推荐阅读
相关标签
  

闽ICP备14008679号