django继承AbstractUser并且关联外健

导入AbstractUser

from django.contrib.auth.models import AbstractUser

项目代码实例

1
2
3
4
5
6
7
8
9
10
11
12
13
class UserModels(AbstractUser):

school = models.ForeignKey(School, on_delete=models.SET_NULL, default=None, null=True)
phone = models.IntegerField(blank=True, default=0)
weixin = models.CharField(max_length=20, blank=True, default=0)
qq = models.IntegerField(blank=True, default=0)
regist_time = models.DateTimeField(auto_now_add=True)

def __str__(self):
return self.username

class Meta:
verbose_name_plural = verbose_name = "用户信息"

项目文件setting.py中加入

AUTH_USER_MODEL = "应用名.UserModels"