from django.contrib.auth.models import AbstractUser의 상속

1242 단어
1. Django의 모델스.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

좋은 웹페이지 즐겨찾기