class Access_rights(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='CASCADE'), nullable=False) category_id = db.Column(db.Integer, db.ForeignKey('category.id', ondelete='CASCADE'), nullable=False) course_id = db.Column(db.Integer, db.ForeignKey('course.id', ondelete='CASCADE'), nullable=False) grant_access = db.Column(db.Boolean, default=False, nullable=False) __table_args__ = (db.UniqueConstraint('user_id', 'category_id', 'course_id'),) def __init__(self, user_id, category_id, course_id, grant_access): self.user_id = user_id self.category_id = category_id self.course_id = course_id self.grant_access = grant_access def __repr__(self): return '<Access rights {} {} {}>'.format(self.user_id, self.category_id, self.course_id)
class Audio(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(1000), nullable=False) lesson_id = db.Column(db.Integer, db.ForeignKey('lesson.id', ondelete='CASCADE'), nullable=False) def __init__(self, name, lesson_id): self.name = name self.lesson_id = lesson_id def __repr__(self): return '<Audio {}>'.format(self.name)
class TextLecture(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(1000), nullable=False) lesson_id = db.Column(db.Integer, db.ForeignKey('lesson.id', ondelete='CASCADE'), nullable=False) text = db.Column(db.Text(1000), nullable=True) def __init__(self, name, lesson_id, text): self.name = name self.lesson_id = lesson_id self.text = text def __repr__(self): return '<TextLecture {}>'.format(self.name)
class Lesson(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) course_id = db.Column(db.Integer, db.ForeignKey('course.id'), nullable=False) description = db.Column(db.Text(1000), nullable=True) videos = db.relationship('Video', backref='lesson', lazy='dynamic') images = db.relationship('Image', backref='lesson', lazy='dynamic') textlectures = db.relationship('TextLecture', backref='lesson', lazy='dynamic') audios = db.relationship('Audio', backref='lesson', lazy='dynamic') __table_args__ = (db.UniqueConstraint('course_id', 'name'),) def __init__(self, name, course_id, description): self.name = name self.course_id = course_id self.description = description def __repr__(self): return '<Lesson {}>'.format(self.name)
class Course(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) category_id = db.Column(db.Integer, db.ForeignKey('category.id'), nullable=False) description = db.Column(db.Text(1000), nullable=True) lessons = db.relationship('Lesson', backref='course', lazy='dynamic') __table_args__ = (db.UniqueConstraint('category_id', 'name'), ) def __init__(self, name, category_id, description): self.name = name self.category_id = category_id self.description = description def __repr__(self): return '<Course {}>'.format(self.name)