1、联表查询

#models.py
class Departement(models.Model):
    '''部门表'''
    title = models.CharField(verbose_name='部门名称', max_length=32)


class UserInfo(models.Model):
    '''员工表'''
    name = models.CharField(verbose_name='姓名', max_length=16)
    passowrd = 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='入职时间')
1.1、联表级联删除(当部门被删除时,同步删除用户表部门信息)
depart = models.ForeignKey(to='Departement',to_field='id',on_delete=models.CASCADE)
1.2、联表置空(当部门被删除时,该字段为空)
    depart = models.ForeignKey(
        to='Departement', to_field='id', null=True, blank=True, on_delete=models.SET_NULL)

2、在Django中做的约束

    gender_choices = (
        (1,'男'),
        (2,'女'),
    )
    gender = models.SmallIntegerField(verbose_name='性别',choices=gender_choices)

3、小数点数值处理

    account = models.DecimalField(
        verbose_name='账户余额', max_digits=10, decimal_places=2, default=0)
#max_digits:最大位数10位
#decimal_places:小数位2位

VIRIYA
1 声望0 粉丝