Django-組件--用戶認證Auth(auth_user增長字段)

from django.contrib.auth.models import AbstractBaseUser


 
 
from django.contrib.auth.models import User  
(user指的是 auth_user表)
User源碼=====》
class User(AbstractUser):
    """
    Users within the Django authentication system are represented by this
    model.

    Username and password are required. Other fields are optional.
    """
    class Meta(AbstractUser.Meta):
        swappable = 'AUTH_USER_MODEL'

一:增長 auth_user 表的字段

1:setting設置

AUTH_USER_MODEL="app01.UserInfo"     #表示哪張表繼承了auth_user表(在給auth_user添加字段用到)

2:增長表字段

from django.contrib.auth.models import AbstractUser

class UserInfo(AbstractUser):
    r_pwd=models.CharField(max_length=32)

3:數據庫遷移

python manage.py makemigrations    #同步
python manage.py migrate

 

4:效果

auth_user 表名被改成  auth_userinfo。且添加了一個字段
相關文章
相關標籤/搜索