学生成绩模型
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
# model/users_api.py
|
||||
# 本文件定义 User 表的结构,映射到 MySQL 数据库
|
||||
|
||||
from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from database import Base
|
||||
|
||||
class Stu_score(Base):
|
||||
"""
|
||||
用户表模型
|
||||
对应 MySQL 中的 users 表
|
||||
"""
|
||||
__tablename__ = "stu_score" # 表名
|
||||
|
||||
# 字段定义
|
||||
id = Column(Integer,primary_key=True, nullable=False,autoincrement=True) #
|
||||
# stu_id = Column(String(10),ForeignKey(stu_info.id),nullable=False) #学生id,非空
|
||||
exam_attempt = Column(Integer, nullable=False) # 考试轮次,非空
|
||||
exam_score = Column(Integer, nullable=False,) # 成绩,非空,设置范围
|
||||
score_level=Column(String(10),nullable=False) #成绩评级
|
||||
is_deleted=Column(Boolean,default=False,nullable=False) #软删除: 0-正常 1-已删除
|
||||
name = relationship("Stu_info", back_populates="score")
|
||||
|
||||
def __repr__(self):
|
||||
return (f"<Stu_info(id={self.stu_id}, exam_attempt='{self.exam_attempt}'"
|
||||
f"exam_score={self.exam_score}, score_level='{self.score_level}'"
|
||||
f"is_deleted={self.is_deleted})>")
|
||||
# created_at:创建时间,自动设置为当前时间(服务器时间)
|
||||
# server_default=func.now() 表示由数据库生成默认值
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
# updated_at:更新时间,当记录更新时自动设置为当前时间(由 SQLAlchemy 的 onupdate 触发)
|
||||
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
Reference in New Issue
Block a user