You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.9 KiB

1 year ago
from django.db import models
from django.core.exceptions import ValidationError
def age_validator(value):
if value < 0:
raise ValidationError('年龄错误太小了')
if value > 150:
raise ValidationError('太老了,还是人吗?')
class BaseUserInfo(models.Model):
id = models.AutoField(verbose_name='编号', primary_key=True)
username = models.CharField(verbose_name='用户名', max_length=30)
password = models.CharField(verbose_name='密码', max_length=20)
status = models.CharField(verbose_name='状态', max_length=1)
create_date = models.DateField(verbose_name='创建日期', auto_now_add=True, db_column='createDate')
def __str__(self):
return str(self.id) + '-' + self.username
class Meta:
db_table = 'orm_user_base_info'
db_table_comment = '人员基本信息'
class DepartInfo(models.Model):
id = models.AutoField(verbose_name='部门编号', primary_key=True)
depart_name = models.CharField(verbose_name='部门名称', max_length=30)
create_date = models.DateField(verbose_name='创建日期', db_column='createDate', auto_now_add=True)
class Meta:
db_table = 'orm_depart_info'
db_table_comment = '部门信息'
class UserExtendInfo(models.Model):
id = models.AutoField(verbose_name='扩展编号', primary_key=True)
username = models.CharField(verbose_name='用户名', max_length=30)
true_name = models.CharField(verbose_name='真实姓名', max_length=30)
sex = models.IntegerField(verbose_name='性别')
age = models.IntegerField(verbose_name='年龄', validators=[age_validator])
department = models.CharField(verbose_name='部门', max_length=20)
salary = models.DecimalField(verbose_name='薪水', max_digits=8, decimal_places=2)
status = models.CharField(verbose_name='状态', max_length=1, db_comment='1 有效, 0 无效')
create_date = models.DateField(verbose_name='创建日期', db_column='createDate', auto_now_add=True)
last_update_time = models.DateTimeField(verbose_name='最后更新时间', db_column='lastUpdateTime', auto_now=True)
memo = models.TextField(verbose_name='备注', blank=True, null=True)
user = models.OneToOneField(BaseUserInfo, on_delete=models.CASCADE)
depart = models.ForeignKey(DepartInfo, default="", on_delete=models.DO_NOTHING)
class Meta:
db_table = 'orm_user_extend_info'
db_table_comment = '人员扩展信息'
class SkillInfo(models.Model):
id = models.AutoField(verbose_name='技能编码', primary_key=True)
skill_name = models.CharField(verbose_name='特长', max_length=30)
create_date = models.DateField(verbose_name='创建时间', db_column='createDate', auto_now_add=True)
user = models.ManyToManyField(UserExtendInfo, db_table='orm_user_skill')
class Meta:
db_table = 'orm_skill_info'
db_table_comment = '技能信息'