• Django Auth组件->扩展用户


    Auth用户

    1.声明用户表

    djangauth/settings.py
    ..............................
    AUTH_USER_MODEL = 'app01.UserInfo'

    2.定义用户表

    app01/models.py

    ..............................

    from django.db import models

    # Create your models here.
    from django.contrib.auth.models import AbstractUser

    class UserInfo(AbstractUser):
    """
    用户信息表
    """
    nid = models.AutoField(primary_key=True)
    phone = models.CharField(max_length=11, null=True, unique=True)

    def __str__(self):
    return self.username

    3.数据库迁移

     python manage.py makemigrations

       python manage.py migrate

    4.查看生成用户表

    -- auto-generated definition
    create table app01_userinfo
    (
    password varchar(128) not null,
    last_login datetime(6) null,
    is_superuser tinyint(1) not null,
    username varchar(150) not null,
    first_name varchar(30) not null,
    last_name varchar(150) not null,
    email varchar(254) not null,
    is_staff tinyint(1) not null,
    is_active tinyint(1) not null,
    date_joined datetime(6) not null,
    nid int auto_increment
    primary key,
    phone varchar(11) null,
    constraint phone
    unique (phone),
    constraint username
    unique (username)
    );

  • 相关阅读:
    模拟退火大法好
    宿命的PSS
    博客在summeroi.top上更新
    SPFA模板
    BZOJ 4551: [Tjoi2016&Heoi2016]树
    BZOJ 4152: [AMPPZ2014]The Captain
    BZOJ 3930: [CQOI2015]选数
    BZOJ 3875: [Ahoi2014&Jsoi2014]骑士游戏
    BZOJ4318: OSU!
    BZOJ3170: [Tjoi 2013]松鼠聚会
  • 原文地址:https://www.cnblogs.com/stonelee2005/p/12101662.html
Copyright © 2020-2023  润新知