Esempio n. 1
0
class Course(Base):
    __tablename__ = 'course'
    lable = models.Column(models.String(32), unique=True)
    teachers = models.relationship('Teachers', backref='to_course')
    # 外表用这个字段,本表用backref
    to_student = models.relationship(
        'Student',
        secondary=Stu_Cou,  #指向多对多表
        backref=models.backref('to_course_ya', lazy='dynamic'),
        lazy='dynamic'  #不加载数据
    )
Esempio n. 2
0
class Course(Base):
    __tablebname__ = "course"
    name = models.Column(models.String(32), unique=True)
    description = models.Column(models.Text)
    to_teacher = models.relationship("Teacher", backref="to_course_data")

    to_student = models.relationship("Students",
                                     secondary=Stu_Cou,
                                     backref=models.backref("to_course",
                                                            lazy="dynamic"),
                                     lazy="dynamic")
Esempio n. 3
0
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,
                                     backref=models.backref('to_course',
                                                            lazy='dynamic'),
                                     lazy='dynamic')
Esempio n. 4
0
class Course(BaseModel):  #课程表
    __tablename = "course"
    label = models.Column(models.String(32))
    description = models.Column(models.Text)
    #双向映射
    to_teachers = models.relationship(  #relationship关联关系relationship
        'Teachers',  #映射类的名称和类名一致#双向映射
        backref='to_course')
    #教师类映射到该表
    #双向映射语法(一对多):字段名=models.relationship(
    #"映射的类名",
    #backref="本表名")
    to_student = models.relationship(
        "Students",
        secondary=Stu_Cou,  #多对多关系表
        backref=models.backref("to_course", lazy="dynamic"),
        lazy="dynamic")
Esempio n. 5
0
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',  #反向映射字段,通过该字段查询当表的内容
        lazy='dynamic')
    #多对多关系查询
    to_students = models.relationship('Students',
                                      secondary=Stu_Cou,
                                      backref=models.backref("to_course",
                                                             lazy='dynamic'),
                                      lazy='dynamic')
Esempio n. 6
0
class Teacher(BaseModel):
    __tablename__ = 'teacher'
    #id = models.Column(models.Integer, primary_key=True, autoincrement=True)
    name = models.Column(models.String(32))  # 老师姓名
    age = models.Column(models.Integer)  # 老师年龄
    gender = models.Column(models.Integer)  # 老师性别0男,1女,-1不知道
    description = models.Column(models.Text)  #老师简介信息
    course_id = models.Column(models.Integer,
                              models.ForeignKey('course.id'))  #专业与老师一对多关系
    # 多对多关系查询
    to_students = models.relationship('Students',
                                      secondary=Stu_Tea,
                                      backref=models.backref("to_teacher",
                                                             lazy='dynamic'),
                                      lazy='dynamic')
    # 与假条表是一对多的关系
    to_ask = models.relationship('Ask', backref='to_teacher')
Esempio n. 7
0
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"  #反向映射字段,映射表通过该字段可以查到当前表内容
    )

    to_student = models.relationship(
        "Students",
        secondary=Stu_Cou,
        backref=models.backref("to_course", lazy="dynamic"),
        lazy="dynamic",
        # lazy 的参数
        # select      访问该字段时候,加载所有的映射数据
        # joined      对关联的两个表students和stu_cou进行join查询
        # dynamic     不加载数据
    )
Esempio n. 8
0
class Course(BaseModel):
    """
    课程表
    """
    __tablename__ = 'course'
    label = models.Column(models.String(32))
    description = models.Column(models.Text)

    #设置双向映射
    to_teacher = models.relationship(  #执行映射表的字段
        'Teacher',  #映射表,映射到谁
        backref='to_course_data'  #反向映射字段
    )

    #多对多
    to_student = models.relationship(
        'Students',
        secondary=Stu_Cou,
        backref=models.backref('to_course', lazy='dynamic'),  #stu_cou course
        lazy='dynamic',  #stu_cou student
        #select  访问该字段的时候加载所有映射数据
        #joined  对关联的两个表student和teacher表进行join查询
        #dynamic 不加载数据,为了防止数据多的时候查询卡
    )