第一次提交
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
from .classes_model import Classes
|
||||
from .student_info import Student
|
||||
from .scores import Scores
|
||||
from .employments import Employments
|
||||
|
||||
__all__ = ["Classes", "Student", "Scores", "Employments"]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,25 @@
|
||||
from sqlalchemy import Column, Integer, String, Boolean, Date, Table, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from database import Base
|
||||
|
||||
|
||||
|
||||
teacher_classes = Table(
|
||||
'teacher_classes',
|
||||
Base.metadata,
|
||||
Column('teacher_id', ForeignKey('teacher.t_id'), primary_key=True),
|
||||
Column('class_id', ForeignKey('classes.class_id'), primary_key=True)
|
||||
)
|
||||
|
||||
class Classes(Base):
|
||||
__tablename__ = 'classes'
|
||||
class_id = Column(Integer, primary_key=True,autoincrement=True)
|
||||
head_teacher_id = Column(Integer, ForeignKey('teacher.t_id'), nullable=False)
|
||||
create_time = Column(Date,nullable=False)
|
||||
class_name = Column(String(50), nullable=False, unique=True)
|
||||
class_delete = Column(Boolean, default=False)
|
||||
counselor_id = Column(Integer, ForeignKey('counselor.id'))
|
||||
|
||||
students = relationship('Student', back_populates='classes')
|
||||
teachers = relationship("Teacher", secondary=teacher_classes, back_populates="classes")
|
||||
counselor = relationship("Counselor", back_populates="classes")
|
||||
@@ -0,0 +1,23 @@
|
||||
#创建顾问表
|
||||
from sqlalchemy import Column, Integer, String, Boolean, Date
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from database import Base
|
||||
|
||||
|
||||
|
||||
class Counselor(Base):
|
||||
__tablename__ = 'counselor'
|
||||
id = Column(Integer, primary_key=True,autoincrement=True)
|
||||
name = Column(String(100),nullable=False,unique=True)
|
||||
c_time = Column(Date,nullable=False) #创建时间
|
||||
c_de = Column(Boolean,default=False) #逻辑判断
|
||||
|
||||
#关联班级表,一对多
|
||||
classes=relationship("Classes",back_populates="counselor")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Counselor(id={self.id}, name={self.name})>"
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
from sqlalchemy import create_engine, Column, Float, String, DateTime, Boolean, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from database import Base
|
||||
# db_url='mysql+pymysql://root:123456@localhost:3306/student_manager'
|
||||
# engine=create_engine(db_url,pool_size=5)
|
||||
#学生就业表
|
||||
class Employments(Base):
|
||||
__tablename__='employments'
|
||||
id = Column(String(20), ForeignKey('students.id'), primary_key=True) #学生id
|
||||
offer_open=Column(DateTime,nullable=True,comment='就业开放时间') #就业开放时间
|
||||
offer_review=Column(DateTime,nullable=True,comment='offer时间') #offer下发时间
|
||||
emp=Column(String(20),nullable=True,comment='就业公司名称') #就业公司名称
|
||||
sal = Column(Float, nullable=True, comment="就业薪资") #就业薪资
|
||||
is_deleted = Column(Boolean, default=False, comment="判断状态") #判断状态
|
||||
student = relationship("Student", back_populates="employment")
|
||||
|
||||
# Base.metadata.drop_all(engine)
|
||||
# Base.metadata.create_all(engine)
|
||||
# SessionLocal=sessionmaker(bind=engine)
|
||||
# # db=SessionLocal()
|
||||
# Base.metadata.create_all(engine)
|
||||
# db.close()
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# 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})>"
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
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})>"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
from sqlalchemy import Column, Integer, String, Boolean, Date
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from database import Base
|
||||
|
||||
|
||||
class Teacher(Base):
|
||||
__tablename__ = 'teacher'
|
||||
t_id = Column(Integer, primary_key=True, autoincrement=True) #老师id
|
||||
t_name = Column(String(50), nullable=False) #老师姓名
|
||||
t_gender = Column(String(50), nullable=False) #性别
|
||||
t_phone = Column(String(50), nullable=False) #手机号
|
||||
t_subject = Column(String(50), nullable=False) #教授科目
|
||||
t_created=Column(Date,nullable=False) #入职时间
|
||||
t_delete = Column(Boolean, default=False) #逻辑判断
|
||||
|
||||
|
||||
#关联表
|
||||
classes=relationship('Classes',secondary='teacher_classes',back_populates='teachers')
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Teacher(t_id={self.t_id}, name='{self.t_name}', subject='{self.t_subject}')>"
|
||||
Reference in New Issue
Block a user