student_id = models.Column(models.Integer, models.ForeignKey('student.id')) # 教师表 class Teacher(BaseModel): __tablename__ = 'teacher' name = models.Column(models.String(32)) age = models.Column(models.Integer) gender = models.Column(models.Integer, default=3) #0 男 1 女 -1 中 course_id = models.Column(models.Integer, models.ForeignKey('course.id')) Stu_Cou = models.Table( 'stu_cou', models.Column('id', models.Integer, primary_key=True, autoincrement=True), models.Column('course_id', models.Integer, models.ForeignKey('course.id')), models.Column('student_id', models.Integer, models.ForeignKey('student.id')), ) # 课程表 class Course(BaseModel): __tablename__ = 'course' lable = models.Column(models.String(32)) description = models.Column(models.Text) to_teacher = models.relationship('Teacher', backref='to_course1') to_student = models.relationship('Student', secondary=Stu_Cou,
identity_id = models.Column(models.Integer,nullable=True) class Students(BaseModel): """ 学员表 """ __tablename__ = "students" name = models.Column(models.String(32)) age = models.Column(models.Integer) gender = models.Column(models.Integer,default = 13) #0 男 1女 -1 unknown Stu_Cou = models.Table( "stu_cou", models.Column("id", models.Integer, primary_key=True, autoincrement=True), models.Column("course_id", models.Integer, models.ForeignKey("course.id")), models.Column("student_id", models.Integer, models.ForeignKey("students.id")) ) class Course(BaseModel): """ 课程表 """ __tablename__ = "course" label = models.Column(models.String(32)) description = models.Column(models.Text) to_teacher = models.relationship( "Teachers", #映射表 backref = "to_course_data", #反向映射字段,反向映射表通过该字段查询当前表内容
__tablename__ = 'students' #学生表名 #id=models.Column(models.Integer,primary_key=True,autoincrement=True)#学生id name = models.Column(models.String(32)) #学生姓名 age = models.Column(models.Integer) #学生年龄 gender = models.Column(models.Integer) #学生性别 has_id = models.Column(models.Integer, nullable=True) #1是有id,0是没有id has_school = models.Column(models.Integer, default=1) #1是有学籍,0是没有学籍 #与考勤表是一对多的关系 to_attendance = models.relationship('Attendance', backref='to_students') #与假条表是一对多的关系 to_ask = models.relationship('Ask', backref='to_students') Stu_Cou = models.Table( "stu_cou", models.Column("id", models.Integer, primary_key=True, autoincrement=True), models.Column("course_id", models.Integer, models.ForeignKey('course.id')), models.Column("student_id", models.Integer, models.ForeignKey('students.id'))) #课程表 class Course(BaseModel): __tablename__ = 'course' # 课程表名 #id = models.Column(models.Integer, primary_key=True, autoincrement=True) lable = models.Column(models.String(32)) description = models.Column(models.Text) updatetime = models.Column(models.DateTime, default=datetime.timezone) #反向映射字段,一对多关系查询 to_teacher = models.relationship( 'Teacher', #映射表 backref='to_course', #反向映射字段,通过该字段查询当表的内容