models.py:python
from django.db import models from django.contrib.auth.models import AbstractUser class UserInfo(AbstractUser): phone = models.CharField(max_length=11) qq_num = models.CharField(max_length=10)
執行命令,更新到數據庫數據庫
能夠看到,該 UserInfo 表繼承了 auth_user 表,並添加了 phone 和 qq_num 字段django
要在 settings.py 中添加相關的配置app
views.py:blog
from django.shortcuts import HttpResponse from app01 import models def reg(request): models.UserInfo.objects.create_superuser(username="admin", password="admin123", email="", phone="13111111171", qq_num="100001") return HttpResponse("註冊成功!")
運行結果:繼承
查看數據庫class
建立成功email