2026-09-21 08:41:49 +08:00
|
|
|
# students_model处理数据库模型
|
|
|
|
|
import datetime
|
|
|
|
|
|
2026-09-22 15:14:32 +08:00
|
|
|
from databases import engine_all,Base_all,Session
|
|
|
|
|
from sqlalchemy import *
|
|
|
|
|
# from students.databases import *
|
2026-09-21 08:41:49 +08:00
|
|
|
from datetime import datetime
|
2026-09-21 18:07:01 +08:00
|
|
|
from sqlalchemy.dialects.mysql import DATETIME
|
2026-09-22 10:08:56 +08:00
|
|
|
from students.schema.students_request import SexEnum , EducationEnum
|
2026-09-22 15:14:32 +08:00
|
|
|
from sqlalchemy import Enum,ForeignKey,Integer,String
|
2026-09-21 08:41:49 +08:00
|
|
|
|
2026-09-22 15:14:32 +08:00
|
|
|
class Students(Base_all):
|
2026-09-21 08:41:49 +08:00
|
|
|
__tablename__ = 'students'
|
2026-09-21 21:49:16 +08:00
|
|
|
id = Column(Integer
|
2026-09-21 08:41:49 +08:00
|
|
|
, primary_key=True
|
|
|
|
|
, autoincrement=True
|
2026-09-21 21:49:16 +08:00
|
|
|
, comment='学生ID,自增主键'
|
|
|
|
|
)
|
2026-09-21 23:11:45 +08:00
|
|
|
num = Column(String(50)
|
2026-09-21 21:49:16 +08:00
|
|
|
, nullable=False
|
|
|
|
|
, unique=True
|
|
|
|
|
, comment='学生编号'
|
2026-09-21 08:41:49 +08:00
|
|
|
)
|
|
|
|
|
|
2026-09-21 23:11:45 +08:00
|
|
|
name = Column(String(50)
|
2026-09-21 21:49:16 +08:00
|
|
|
, comment='学生姓名'
|
|
|
|
|
, nullable=False )
|
2026-09-21 08:41:49 +08:00
|
|
|
|
2026-09-21 21:49:16 +08:00
|
|
|
age = Column(Integer
|
|
|
|
|
, comment='年龄'
|
|
|
|
|
, nullable=False)
|
2026-09-21 08:41:49 +08:00
|
|
|
|
2026-09-22 10:08:56 +08:00
|
|
|
sex = Column(Enum(SexEnum, values_callable=lambda e: [i.value for i in e])
|
2026-09-21 21:49:16 +08:00
|
|
|
, comment='性别'
|
|
|
|
|
, nullable=False)
|
2026-09-21 08:41:49 +08:00
|
|
|
|
2026-09-21 21:49:16 +08:00
|
|
|
home_Place = Column(String(50)
|
|
|
|
|
, comment='籍贯')
|
2026-09-21 08:41:49 +08:00
|
|
|
|
2026-09-21 21:49:16 +08:00
|
|
|
college = Column(String(50)
|
|
|
|
|
, comment='毕业院校')
|
2026-09-21 08:41:49 +08:00
|
|
|
|
2026-09-21 21:49:16 +08:00
|
|
|
specialty = Column(String(50)
|
|
|
|
|
, comment='专业')
|
2026-09-21 08:41:49 +08:00
|
|
|
|
2026-09-21 21:49:16 +08:00
|
|
|
enrollment_time = Column(DATETIME
|
|
|
|
|
, comment='入学时间')
|
2026-09-21 08:41:49 +08:00
|
|
|
|
2026-09-21 21:49:16 +08:00
|
|
|
graduate_time = Column(DATETIME
|
|
|
|
|
, comment='毕业时间')
|
2026-09-21 08:41:49 +08:00
|
|
|
|
2026-09-22 10:08:56 +08:00
|
|
|
education = Column(Enum(EducationEnum, values_callable=lambda e: [i.value for i in e])
|
|
|
|
|
, comment='学历'
|
|
|
|
|
, nullable=True)
|
2026-09-21 08:41:49 +08:00
|
|
|
|
2026-09-21 21:49:16 +08:00
|
|
|
# 外键字段
|
|
|
|
|
class_id = Column(Integer
|
2026-09-22 15:14:32 +08:00
|
|
|
, ForeignKey("classes.id")
|
|
|
|
|
, comment='学生班级'
|
|
|
|
|
, nullable=False )
|
2026-09-21 08:41:49 +08:00
|
|
|
|
2026-09-22 10:08:56 +08:00
|
|
|
advisor_id = Column(Integer
|
2026-09-22 15:14:32 +08:00
|
|
|
, ForeignKey("teachers.id")
|
2026-09-21 21:49:16 +08:00
|
|
|
, comment='顾问ID')
|
|
|
|
|
|
|
|
|
|
# 额外字段
|
|
|
|
|
phone = Column(String(11)
|
|
|
|
|
, comment='学生手机号'
|
|
|
|
|
, nullable=False
|
|
|
|
|
, unique=True )
|
|
|
|
|
|
|
|
|
|
# 通用字段
|
|
|
|
|
create_date = Column(DATETIME(fsp=6)
|
|
|
|
|
, default=datetime.now
|
|
|
|
|
, comment='创建时间' )
|
|
|
|
|
|
|
|
|
|
update_date = Column(DATETIME(fsp=6)
|
|
|
|
|
, default=datetime.now
|
|
|
|
|
, comment='更新时间' )
|
|
|
|
|
|
|
|
|
|
is_deleted = Column(INTEGER
|
|
|
|
|
, default=False
|
|
|
|
|
, comment='是否删除:0-正常,1-已删除' )
|
|
|
|
|
|
|
|
|
|
deleted_date = Column(DATETIME(fsp=6)
|
|
|
|
|
, default=None
|
|
|
|
|
, comment='删除时间' )
|
2026-09-21 08:41:49 +08:00
|
|
|
|