创建新项目,及应用
django-admin startproject myproj
cd myproj
python manage.py startapp myapp
自定义 User 类
文件myapp/models.py
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
name = models.CharField(blank=True, max_length=255)
文件 myproj/settings.py
INSTALLED_APPS = [
...
'myapp',
]
AUTH_USER_MODEL = 'myapp.User'
文件 myproj/admin.py
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User
admin.site.register(User, UserAdmin)
更新数据库
python manage.py makemigrations myapp
python manage.py migrate
// python manage.py createsuperuser