38 lines
1.9 KiB
Python
38 lines
1.9 KiB
Python
# from sqlalchemy import Column, Integer, Boolean, ForeignKey,String
|
||
# from sqlalchemy.orm import relationship
|
||
# from database import Base
|
||
# class Scores(Base): # 学生考核成绩管理表模型
|
||
# __tablename__ = "scores"
|
||
# scores_id = Column(Integer, primary_key=True, autoincrement=True) # 成绩自增长序号 是本表主键(1,2,3,4,5,6)
|
||
# id = Column(String(30), ForeignKey('student.id')) #学生ID 是Student表的外键(1,1,1,2,2,2)
|
||
# exam_round = Column(Integer, nullable=False) #考核序次 不唯一(1,2,3,1,2,3)
|
||
# score = Column(Integer) #成绩 不唯一 可None
|
||
# is_warning= Column(Boolean, default=False) #成绩红线预警 默认没预警 (高于60写入"True",低于60写入"False")
|
||
# is_deleted = Column(Boolean, default=False) #逻辑删除标记 默认没删除 (删除写入"True",不删除写入"False")
|
||
#
|
||
# student = relationship("Student", back_populates="scores") # 外键 多对一 关联Student
|
||
# def __repr__(self): # 魔法方法打印展示学生ID、对应序次的成绩
|
||
# return f"<Scores(学生ID:{self.id}, 考核序次:{self.exam_round}, 成绩:{self.score})>"
|
||
|
||
from sqlalchemy import Column, Integer, Boolean, ForeignKey, String
|
||
from sqlalchemy.orm import relationship
|
||
from database import Base
|
||
|
||
|
||
class Scores(Base):
|
||
__tablename__ = "scores"
|
||
|
||
scores_id = Column(Integer, primary_key=True, autoincrement=True)
|
||
id = Column(String(20), ForeignKey('students.id')) # ← 关键修复
|
||
exam_round = Column(Integer, nullable=False)
|
||
score = Column(Integer)
|
||
is_warning = Column(Boolean, default=False)
|
||
is_deleted = Column(Boolean, default=False)
|
||
|
||
student = relationship("Student", back_populates="scores")
|
||
|
||
def __repr__(self):
|
||
return f"<Scores(学生ID:{self.id}, 考核序次:{self.exam_round}, 成绩:{self.score})>"
|
||
|
||
|