from django.db import models
# Create your models here.
class Department(models.Model): # 以后可以新增,删除,修改,所以单独拿出来
""" 部门表 """
title = models.CharField(verbose_name='标题', max_length=32)
def __str__(self): # 原来是对象,用来定义我们想返回的值
return self.title
class UserInfo(models.Model):
""" 员工表 """
name = models.CharField(verbose_name="姓名", max_length=16)
password = models.CharField(verbose_name="密码", max_length=64)
age = models.IntegerField(verbose_name="年龄")
account = models.DecimalField(
verbose_name="账户余额", max_digits=10, decimal_places=2, default=0)
# create_time = models.DateTimeField(verbose_name="入职时间") # 年月日,时分秒
create_time = models.DateField(verbose_name="入职时间") # 年月日
# 1.无约束
# depart_id = models.BigIntegerField(verbose_name="部门ID")
# 有约束
# - to ,与那章表关联
# - to_field ,表中的那一列关联
# 2.django自动
# - 写的depart
# - 生成数据列 depart_id
# 3.部门表被删除
# ### 3.1级联删除 on_delete=models.CASCADE 级联删除
depart = models.ForeignKey(verbose_name="部门",
to="Department", to_field="id", on_delete=models.CASCADE)
# ### 3.2置空
# null=True, blank=True, 这一列允许为空 on_delete=models.SET_NULL 置空
# depart = models.ForeignKey(
# to="Department", to_field="id", null=True, blank=True, on_delete=models.SET_NULL)
# 在 django中的约束
gender_choices = (
(1, "男"),
(2, "女"),
)
gender = models.SmallIntegerField(
verbose_name="性别", choices=gender_choices)
# level_choices = (
# (1, "1级"),
# (2, "2级"),
# (3, "3级"),
# (4, "4级"),
# )
# # SmallIntegerField 小整形(小整数) default=1 默认是1
# level = models.SmallIntegerField(
# verbose_name="级别", choices=level_choices, default=1)
class PrettyNum(models.Model):
""" 靓号管理 """
# CharField 存储为字符串类型 必须设置长度,校验,re,收索
mobile = models.CharField(
verbose_name="手机号", max_length=11)
# IntegerField 整数 不用设置长度
# 想要允许为空 null=True,blank=True
price = models.IntegerField(verbose_name="价格")
levels_choices = (
(1, "1级"),
(2, "2级"),
(3, "3级"),
(4, "4级"),
)
# SmallIntegerField 小整形(小整数) default=1 默认是1
levels = models.SmallIntegerField(
verbose_name="级别", choices=levels_choices, default=1)
status_choices = (
(1, "已占用"),
(2, "未占用"),
)
status = models.SmallIntegerField(
verbose_name="状态", choices=status_choices, default=2)