学生信息管理系统
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
from sqlalchemy import Column, Integer,ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from database import Base
|
||||
|
||||
|
||||
# 成绩表表模型
|
||||
class Score(Base):
|
||||
__tablename__ = 'score'
|
||||
# 联合主键stu_id,exam_order
|
||||
# 外键关联student
|
||||
stu_id=Column(Integer,ForeignKey('student.stu_id'),primary_key=True)
|
||||
# 声明关联student
|
||||
student=relationship('Student',back_populates='score')
|
||||
exam_id=Column(Integer,primary_key=True)
|
||||
score=Column(Integer,nullable=False)
|
||||
|
||||
|
||||
|
||||
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,14 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Column, Integer, String, DateTime
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from database import Base
|
||||
#创建顾问老师表模型。
|
||||
class Advisor(Base):
|
||||
__tablename__ = 'advisor'
|
||||
advisor_id = Column(Integer, primary_key=True,autoincrement=False)
|
||||
advisor_name = Column(String(50),nullable=False)
|
||||
#引入时间模块,得到创建时时间。特别注意这里,datetime点now不能有括号,有括号时,就在创建这个表类的时候,就锚定了时间。
|
||||
#不写括号的话,就是当这个生成实例的时候,也就是具体往表里面注入内容的时候,才会生成一个对应的时间。
|
||||
# 反向关系:Student.advisor 的对端(属性名必须是 students,与 Student.advisor 的 back_populates 一致)
|
||||
students = relationship("Student", back_populates="advisor")
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
|
||||
from sqlalchemy import Column, Integer, Date # 导入"列"和字段类型(整数、日期)
|
||||
from sqlalchemy.orm import relationship # 导入"关系"函数,用来定义表间关联
|
||||
from database import Base # 导入database.py里的Base基类
|
||||
|
||||
|
||||
class Classinfo(Base):# 定义ORM模型类,继承Base,SQLAlchemy才知道它对应一张表
|
||||
# 表名必须和建表语句一致:c_lass
|
||||
__tablename__ = "c_lass" # 指定表名,必须和MySQL里的表名一模一样,否则连不上表
|
||||
|
||||
class_id = Column(Integer, primary_key=True, index=True) # 主键列:整数类型;index=True表示建索引,按这个字段查会更快
|
||||
start_time = Column(Date, nullable=False) # 开班日期:日期类型;nullable=False = 不能为空(数据库层面强制)
|
||||
# 逻辑删除:0未删除,1已删除,默认0
|
||||
is_deleted = Column(Integer, nullable=False, default=0)
|
||||
|
||||
# 反向关系:Student.my_class / Teacher.classes 的对端
|
||||
students = relationship("Student", back_populates="my_class")
|
||||
# 声明关系:一个班级下有很多学生(一对多)。"Student"是字符串,指向学生模型
|
||||
# back_populates="my_class":和Student模型里的my_class属性互相呼应
|
||||
teachers = relationship("Teacher", back_populates="classes")
|
||||
# 同样:一个班级下有很多老师
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#导入创造引擎、定义类模块、数据类型模块、连接符模块
|
||||
from sqlalchemy import Column, Integer, String, Date, Float, ForeignKey
|
||||
#导入基类
|
||||
from database import Base
|
||||
#定义就业基础模块
|
||||
class EmploymentBase(Base):
|
||||
__tablename__="employment_base"
|
||||
stu_id=Column(Integer,ForeignKey("student.stu_id"),primary_key=True)
|
||||
employment_open_time=Column(Date)
|
||||
job_time=Column(Date)
|
||||
company_name=Column(String(100))
|
||||
salary=Column(Float)
|
||||
is_deleted=Column(Integer,default=0)
|
||||
#定义就业协议模块
|
||||
class EmploymentOffer(Base):
|
||||
__tablename__="employment_offer"
|
||||
stu_id=Column(Integer,primary_key=True)
|
||||
offer_id=Column(Integer,primary_key=True)
|
||||
offer_time=Column(Date)
|
||||
is_deleted=Column(Integer,default=0)
|
||||
@@ -0,0 +1,41 @@
|
||||
# model/users.py
|
||||
# 本文件定义 User 表的结构,映射到 MySQL 数据库
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Float, ForeignKey,DateTime,Date
|
||||
from sqlalchemy.orm import declarative_base,relationship
|
||||
from sqlalchemy.sql import func
|
||||
from database import Base
|
||||
|
||||
|
||||
# model 类,对应 student表
|
||||
class Student(Base):
|
||||
__tablename__ = "student" #指定表名
|
||||
|
||||
stu_id = Column(Integer, primary_key = True) #主键,学生编号
|
||||
stu_name = Column(String(10),nullable = False) #学生名字,非空约束
|
||||
native_place = Column(String(30),nullable = False) #籍贯,非空
|
||||
graduate_school = Column(String(50),nullable = False) #毕业院校
|
||||
major = Column(String(20),nullable = False) #专业
|
||||
enroll_time = Column(Date, comment = "入学时间",nullable = False)
|
||||
graduate_time = Column(Date, comment = "毕业时间",nullable = False)
|
||||
education = Column(String(10),nullable = False) #学历,非空
|
||||
age = Column(Integer,nullable = False) #年龄
|
||||
gender = Column(String(10),nullable = False) #性别
|
||||
# employment_open_time = Column(Date,nullable = False) #简历开放时间
|
||||
# company_name = Column(String(100),nullable = False) #公司名称
|
||||
# salary = Column(Float,nullable = False) #薪资
|
||||
# # 逻辑删除标记
|
||||
is_deleted = Column(Integer, nullable=False,default=0, comment="0正常;1逻辑删除")
|
||||
# 外键:关联 C_lass 的 id
|
||||
class_id = Column(Integer, ForeignKey("c_lass.class_id"), nullable=False)
|
||||
# 关系属性:关联 Classinfo
|
||||
my_class = relationship("Classinfo", back_populates="students")
|
||||
# 外键:关联Advisor的id
|
||||
advisor_id = Column(Integer,ForeignKey("advisor.advisor_id"),nullable=False)
|
||||
# 关系属性:关联Advisor
|
||||
advisor = relationship("Advisor", back_populates="students")
|
||||
# 关系属性:关联成绩(Score.student 的对端)
|
||||
score = relationship("Score", back_populates="student")
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# 与数据库的表进行关联
|
||||
# 导入database文件,这里已经创建基类
|
||||
from sqlalchemy import Column, Integer, ForeignKey, String
|
||||
from sqlalchemy.orm import relationship
|
||||
from database import Base
|
||||
# 关联数据库中的teacher表
|
||||
class Teacher(Base):
|
||||
__tablename__ = 'teacher'
|
||||
teacher_id = Column(Integer, primary_key=True)
|
||||
class_id = Column(Integer,ForeignKey('c_lass.class_id'),nullable=False)
|
||||
teacher_name = Column(String(50),nullable=False)
|
||||
job_name=Column(String(50),nullable=False,comment='主讲、班主任、助教')
|
||||
is_deleted = Column(Integer, default=0, nullable=False)
|
||||
classes=relationship("Classinfo",back_populates="teachers")
|
||||
def __repr__(self):
|
||||
return f"<Teacher(teacher_id={self.teacher_id},class_id={self.class_id},teacher_name='{self.teacher_name}',job_name='{self.job_name}')>"
|
||||
Reference in New Issue
Block a user