Exemplo n.º 1
0
class Attendance(BaseNodel):
    #考勤表
    __tablename__ = 'attendance'

    att_time = models.Column(models.Date)
    status = models.Column(models.Integer, default=1)  # 0 迟到  1 正常出勤  2 早退  3 请假  4 旷课
    student_id = models.Column(models.Integer, models.ForeignKey("students.id"))#外键字段是学生表
Exemplo n.º 2
0
class Grade(BaseNodel):
    #成绩表
    __tablename__ = 'grade'

    grade = models.Column(models.Float, default=0)
    course_id = models.Column(models.Integer, models.ForeignKey("course.id"))
    student_id = models.Column(models.Integer, models.ForeignKey("students.id"))#外键关系是学生
Exemplo n.º 3
0
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
Exemplo n.º 4
0
class Teacher(BaseNodel):
    #老师表
    __tablename__ = 'teacher'

    name = models.Column(models.String(32))
    age = models.Column(models.Integer)
    gender = models.Column(models.Integer)  # 0 男 1女 -1 unknown
    course_id = models.Column(models.Integer, models.ForeignKey("course.id"))#外键字段的搭建对应的课程表
Exemplo n.º 5
0
class Grade(BaseModel):
    """
    成绩表
    课程,学员关联此表
    """
    __tablename__ = "grade"
    grade = models.Column(models.Float, default=0)
    course_id = models.Column(models.Integer, models.ForeignKey("course.id"))
    student_id = models.Column(models.Integer, models.ForeignKey("students.id"))
Exemplo n.º 6
0
class Attendance(BaseModel):
    """
    考勤表,记录是否请假
    学员
    """
    __tablename__ = "attendance"
    att_time = models.Column(models.Date)
    status = models.Column(models.Integer,default = 1) #0 迟到  1 正常出勤  2 早退  3 请假  4 旷课
    student_id = models.Column(models.Integer, models.ForeignKey("students.id"))
Exemplo n.º 7
0
class Teachers(BaseModel):
    """
    教师
    老师与课程是多对一关系
    """
    __tablename__ = "teachers"
    name = models.Column(models.String(32))
    age = models.Column(models.Integer)
    gender = models.Column(models.Integer,default = 3)  # 0 男 1女 -1 unknown
    course_id = models.Column(models.Integer, models.ForeignKey("course.id")) #教师多对一 映射表是课程
Exemplo n.º 8
0
class Student(BaseNodel):
    #学生表
    __tablename__ = 'students'
    name = models.Column(models.String(32))
    age = models.Column(models.Integer)
    gender = models.Column(models.Integer)#0男 1女
    to_attendance = models.relationship(
        'Attendance',#考勤的方法名
        backref = 'to_student_hh'#反向字段
    )
Exemplo n.º 9
0
class BaseModel(models.Model):
    __abstract__ = True #抽象表为True,代表当前类为抽象类,不会被创建
    id = models.Column(models.Integer, primary_key=True, autoincrement=True)

    def save(self):
        session.add(self)
        session.commit()
    def delete_obj(self):
        session.delete(self)
        session.commit()
Exemplo n.º 10
0
class BaseNodel(models.Model):
    __abstract__ = True#代表当前类是抽象的,不会被创建
    id = models.Column(models.Integer,primary_key=True,autoincrement=True)
    #保存数据的方法
    def save(self):
        session.add(self)
        session.commit()#固定用法
    def delete_object(self):
        session.delete(self)
        session.commit()
Exemplo n.º 11
0
class Course(BaseNodel):
    #课程表
    __tablename__ = 'course'

    label = models.Column(models.String(32))
    description = models.Column(models.Text)
    to_teacher = models.relationship(
        'Teacher',#隐射
        backref = 'to_course_data'#反向字段teacher 查询课程的字段
    )
    to_student = models.relationship(
        'Student',#方法名
        secondary = Stu_Cou,
        backref = models.backref('to_course',lazy = 'dynamic'),#反向字段(stu_cou studens)
        lazy = 'dynamic'#(stu_cou course)
        # select 访问该字段时候,加载所有的映射数据
        # joined  对关联的两个表students和stu_cou进行join查询
        # dynamic 不加载数据
    )
Exemplo n.º 12
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"), #stu_cou course
        lazy = "dynamic" #stu_cou student
        #select 访问该字段时候,加载所有的映射数据
        #joined  对关联的两个表students和stu_cou进行join查询
        #dynamic 不加载数据
    )
Exemplo n.º 13
0
class User(BaseModel):
    __tablename__ = "user"
    username = models.Column(models.String(32))
    password = models.Column(models.String(32))
    identity = models.Column(models.Integer) #0 学员 #1 教师
    identity_id = models.Column(models.Integer,nullable=True)
Exemplo n.º 14
0
    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",  #映射表