zoukankan      html  css  js  c++  java
  • Django 自定义表

    1.Django自带的用户表

    create table auth_user
    (
      id           int auto_increment
        primary key,
      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(30)  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,
      constraint username
      unique (username)
    );

    2.创建自定义表models.User

    from django.contrib.auth.models import AbstractUser
    class User(AbstractUser):
        """用户模型类"""
        mobile = models.CharField(max_length=11, verbose_name='手机号')
    
        class Meta:
            db_table = 'tb_users'
            verbose_name = "用户信息表"
            verbose_name_plural = verbose_name
    
        def __str__(self):
            return self.username

    3.注册自定义表 admin.UserAdmin

    from django.contrib import admin
    from .models import User
    
    class Useradmin(admin.ModelAdmin):
        list_display = ['username', 'password', 'mobile']
    # Register your models here.
    admin.site.register(User, Useradmin)  # 用UserAdmin去注册User

    4.settings添加user表

    #自定义用户表
    AUTH_USER_MODEL = 'app名字.User'

    5.登录后台查看

  • 相关阅读:
    git clone失败
    矩阵相乘
    pandas中关于DataFrame 去除省略号
    Linux系统清除缓存
    Git 远程仓库 更新url
    看不到git远程分支
    c++
    undefined reference to symbol' pthread_create@@GLIBC_2.2.5'
    ssh 与远程机器保持心跳(linux)
    python 读取文件第一列 空格隔开的数据
  • 原文地址:https://www.cnblogs.com/icemonkey/p/10540215.html
Copyright © 2011-2022 走看看