Files
2026-09-21 17:39:16 +08:00

35 lines
1.6 KiB
Python

from sqlalchemy import Column, String, Integer, Date, Boolean, ForeignKey
from sqlalchemy.orm import relationship
from database import Base
class Student(Base):
__tablename__ = "students"
id = Column(String(20), primary_key=True, comment="学号")# 主键:学号
name = Column(String(50), nullable=False, comment="学生姓名")
gender = Column(String(10), nullable=False, comment="性别:男 / 女")
age = Column(Integer, comment="年龄")
hometown = Column(String(100), comment="籍贯")
graduate_school = Column(String(100), comment="毕业学校")
major = Column(String(50), comment="专业")
education = Column(String(30), comment="专科/本科/硕士")
enrollment_date = Column(Date, comment="入学时间")
graduation_date = Column(Date, comment="毕业时间")
status = Column(String(20), default="在读", comment="状态:没有毕业/未就业/已就业")
is_deleted = Column(Boolean, default=False, comment="逻辑删除标记")
# 外键 班级编号
class_name = Column(String(20), ForeignKey("classes.class_name"), comment="所属班级编号")
# 关系映射 学生和就业 一对一,一个学生对应一条就业信息 学生和成绩一对多,一个学生对应多条成绩
scores = relationship("Scores", back_populates="student") # 一个学生多次考核成绩
employment = relationship("Employments", back_populates="student", uselist=False) # 一对一就业信息
classes = relationship("Classes", back_populates="students")
def __repr__(self):
return f"<Student(no={self.id}, name={self.name}, class={self.class_name})>"