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.登录后台查看

  • 相关阅读:
    HDU 2073 无限的路
    HDU 2080 夹角有多大II
    if
    HDU 2094 产生冠军
    HDU 2076 夹角有多大(题目已修改,注意读题)
    HDU 2086 A1 = ?
    HDU 2069 Coin Change
    HDU 2095 find your present (2)
    android常用开发工具的用法
    android安装前期遇到的问题
  • 原文地址:https://www.cnblogs.com/icemonkey/p/10540215.html
Copyright © 2011-2022 走看看