from django.db import models

# Create your models here.
class Dept(models.Model):
    """部门类"""

    no = models.IntegerField(primary_key=True,db_column='dno',verbose_name="部门编号")
    name = models.CharField(max_length=20,db_column='dname',verbose_name='部门名称')
    location = models.CharField(max_length=10,db_column='dloc',verbose_name='部门所在地')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'tb_dept'


class Emp(models.Model):
    """员工类"""

    no = models.IntegerField(primary_key=True, db_column='eno', verbose_name="员工编号")
    name = models.CharField(max_length=20, db_column='ename', verbose_name='员工姓名')
    job = models.CharField(max_length=10, verbose_name='职位')

    # 多对一外键关联(自参照)
    mgr = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, verbose_name='主管')
    sal = models.DecimalField(max_digits=7,decimal_places=2,verbose_name="月薪")
    comm = models.DecimalField(max_digits=7,decimal_places=2,null=True,blank=True,verbose_name="补贴")
    # 多对一外键关联(参照部门模型)
    dept = models.ForeignKey(to=Dept,on_delete=models.PROTECT,db_column="dno",verbose_name="所在部门")
    def __str__(self):
        return self.name

    class Meta:
        db_table = 'tb_emp'

from django.db import models

# Create your models here.
class Dept(models.Model):
    """部门类"""

    no = models.IntegerField(primary_key=True,db_column='dno',verbose_name="部门编号")
    name = models.CharField(max_length=20,db_column='dname',verbose_name='部门名称')
    location = models.CharField(max_length=10,db_column='dloc',verbose_name='部门所在地')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'tb_dept'


class Emp(models.Model):
    """员工类"""

    no = models.IntegerField(primary_key=True, db_column='eno', verbose_name="员工编号")
    name = models.CharField(max_length=20, db_column='ename', verbose_name='员工姓名')
    job = models.CharField(max_length=10, verbose_name='职位')

    # 多对一外键关联(自参照)
    mgr = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, verbose_name='主管')
    sal = models.DecimalField(max_digits=7,decimal_places=2,verbose_name="月薪")
    comm = models.DecimalField(max_digits=7,decimal_places=2,null=True,blank=True,verbose_name="补贴")
    # 多对一外键关联(参照部门模型)
    dept = models.ForeignKey(to=Dept,on_delete=models.PROTECT,db_column="dno",verbose_name="所在部门")
    def __str__(self):
        return self.name

    class Meta:
        db_table = 'tb_emp'

# Create your models here. 部门类 员工类 # 多对一外键关联(自参照) # 多对一外键关联(参照部门模型)