Beispiel #1
0
class Comments(db.Model):
    __table_args__ = {"useexisting": True}

    id = db.Column(db.Integer, primary_key=True)
    # 评论内容
    content = db.Column(db.Text, nullable=False)
    # 评论用户
    from_user = db.relationship("User", back_populates="comments")
    from_user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    # 评论发布日期
    send_time = db.Column(db.DateTime, default=datetime.utcnow)
    # 评论是否是回复
    is_reply = db.Column(db.Boolean, default=False)
    # 评论属于的讨论
    belong_talking = db.relationship("Talkings", back_populates="comments")
    belong_talking_id = db.Column(db.Integer, db.ForeignKey("talkings.id"))
    # 被回复的评论id
    replied_id = db.Column(db.Integer, db.ForeignKey("comments.id"))
    # 被回复的评论
    replied = db.relationship("Comments",
                              back_populates="replies",
                              remote_side=[id])
    # 该评论的所有回复
    replies = db.relationship("Comments",
                              back_populates="replied",
                              cascade="all")
Beispiel #2
0
class Notices(db.Model):
    __table_args__ = {"useexisting": True}
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255), nullable=False)
    content = db.Column(db.Text, nullable=False)
    belong_class = db.relationship("Class", back_populates="notices")
    belong_class_id = db.Column(db.Integer, db.ForeignKey("class.id"))
    create_time = db.Column(db.DateTime, default=datetime.utcnow)
Beispiel #3
0
class FinishStatus(db.Model):
    __table_args__ = {"useexisting": True}

    # id
    id = db.Column(db.Integer, primary_key=True)
    # 作业,与作业表关联
    assignment = db.relationship("Assignment", back_populates="finish_status")
    assignment_id = db.Column(db.Integer, db.ForeignKey("assignment.id"))
    # 提交用户,与用户表关联
    finish_user = db.relationship("User", back_populates="assignments")
    finish_user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    # 提交内容
    finish_content = db.Column(db.Text, nullable=False)
    # 提交时间
    finish_time = db.Column(db.DateTime, default=datetime.utcnow)
    # 作业得分,默认表示暂无得分
    score = db.Column(db.Integer, nullable=False, default=0)
    # 该作业是否已批改
    is_correct = db.Column(db.Integer, nullable=False, default=0)
Beispiel #4
0
class Talkings(db.Model):
    __table_args__ = {"useexisting": True}

    # id
    id = db.Column(db.Integer, primary_key=True)
    # 讨论题目
    title = db.Column(db.String(255), nullable=False)
    # 讨论内容
    content = db.Column(db.Text, nullable=False)
    # 讨论回复,与评论类关联
    comments = db.relationship("Comments",
                               back_populates="belong_talking",
                               cascade="all")
    # 讨论所属班级
    belong_class = db.relationship("Class", back_populates="talkings")
    belong_class_id = db.Column(db.Integer, db.ForeignKey("class.id"))
    # 公开时间
    publish_time = db.Column(db.DateTime, default=datetime.utcnow)
    # 发起用户
    publish_user = db.relationship("User", back_populates="talkings")
    publish_user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
Beispiel #5
0
class Assignment(db.Model):
    __table_args__ = {"useexisting": True}
    # 作业id
    id = db.Column(db.Integer, primary_key=True)
    # 作业标题
    title = db.Column(db.String(255), nullable=False)
    # 作业内容 -->
    content = db.Column(db.Text, nullable=False)
    # 作业发布日期
    publish_date = db.Column(db.DateTime, default=datetime.utcnow)
    # 作业所属目录,与SecondCategory表关联
    belong_category = db.relationship("SecondCategory",
                                      back_populates="assignment")
    belong_category_id = db.Column(db.Integer,
                                   db.ForeignKey("second_category.id"))
    # 作业所属的班级
    belong_class = db.relationship("Class", back_populates="assignments")
    belong_class_id = db.Column(db.Integer, db.ForeignKey("class.id"))
    # 作业选择题对应的答案-->"A,B,C"
    answer = db.Column(db.String(255))
    # 该作业的完成情况
    finish_status = db.relationship("FinishStatus",
                                    back_populates="assignment",
                                    cascade="all")
Beispiel #6
0
class FirstCategory(db.Model):
    __table_args__ = {"useexisting": True}
    __tablename__ = "first_category"
    id = db.Column(db.Integer, primary_key=True)
    # 目录名
    name = db.Column(db.String(255))
    # 该目录属于的班级
    belong_class = db.relationship("Class", back_populates="categories")
    belong_class_id = db.Column(db.Integer, db.ForeignKey("class.id"))
    # 该目录下的二级目录
    sub_categories = db.relationship("SecondCategory",
                                     back_populates="parent_category",
                                     cascade="all")
    # 下一个一级目录的id,若下一个没有了则为0
    next_category_id = db.Column(db.Integer, default=0)
    # 该目录是否是第一个目录
    is_first_category = db.Column(db.Boolean, default=False)
Beispiel #7
0
class SecondCategory(db.Model):
    __table_args__ = {"useexisting": True}

    __tablename__ = "second_category"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))
    # 属于的父级目录
    parent_category = db.relationship("FirstCategory",
                                      back_populates="sub_categories")
    parent_category_id = db.Column(db.Integer,
                                   db.ForeignKey("first_category.id"))
    # 该目录对应的视频地址
    movie = db.Column(db.String(255))
    # 该二级目录对应的作业
    assignment = db.relationship("Assignment",
                                 back_populates="belong_category",
                                 cascade="all")
    # 该二级目录添加的时间
    add_time = db.Column(db.DateTime, default=datetime.utcnow)
Beispiel #8
0
    # 简介
    info = db.Column(db.String(255), default="该用户未填写简介~")
    # 性别,True为男
    gender = db.Column(db.Boolean, nullable=False, default=True)
    # 创建时间
    create_time = db.Column(db.DateTime, default=datetime.utcnow)
    # 用户头像
    avatar = db.Column(db.String(255), default="default")
    # 总学习时长
    total_study = db.Column(db.Integer, default=0)


# User 与 Class建立多对多关系
association_table = db.Table('association',
                             db.Column('user_id', db.Integer,
                                       db.ForeignKey("user.id")),
                             db.Column('class_id', db.Integer,
                                       db.ForeignKey("class.id")),
                             extend_existing=True)


# 用户表
class User(db.Model, BaseModel):
    __table_args__ = {"useexisting": True}
    # 用户班级,与Class表外键关联
    user_classes = db.relationship("Class",
                                   back_populates="stds",
                                   secondary=association_table)
    # 用户作业,集合属性,与作业状态表关联
    assignments = db.relationship("FinishStatus",
                                  back_populates="finish_user",