class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='def.png') password = db.Column(db.String(60), nullable=False) posts = db.relationship('Post', backref='author', lazy=True) courses = db.relationship('Course', backref='teacher', lazy=True) comments = db.relationship('Comment', backref='commenter', lazy=True) def get_reset_token(self, expires_sec=1800): s = Serializer(app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class Topic(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) start_date = db.Column(db.DateTime, default=datetime.utcnow) end_date = db.Column(db.DateTime) homeworks = db.relationship('Homework', backref='topic', lazy=True) tests = db.relationship('Test', backref='topic', lazy=True) def __repr__(self): return f"Topic('{self.name}')"
class Student(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) email = db.Column(db.String(35)) address = db.Column(db.Text) parent_phone = db.Column(db.String(35)) predicted_grade = db.Column(db.String(35)) homework_marks = db.relationship('HomeworkMark', backref='student', lazy=True) test_marks = db.relationship('TestMark', backref='student', lazy=True) exam_marks = db.relationship('ExamMark', backref='student', lazy=True) def __repr__(self): return f"Student('{self.name}', '{self.email}', '{self.address}', '{self.parent_phone}', '{self.predicted_grade}')"
class Course(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) start_date = db.Column(db.DateTime, default=datetime.utcnow) year_num = db.Column(db.Integer, nullable=False) grading_system = db.Column(db.String(10), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) classes = db.relationship('Class', backref='course', lazy=True) topics = db.relationship('Topic', backref='course', lazy=True) exams = db.relationship('Exam', backref='course', lazy=True) def __repr__(self): return f"Course('{self.name}', '{self.grading_system}')"
class Class(db.Model): id = db.Column(db.Integer, primary_key=True) class_name = db.Column(db.String(100), nullable=False) class_starting_date = db.Column(db.DateTime, nullable=False) course_id = db.Column(db.Integer, db.ForeignKey('course.id'), nullable=False) students = db.relationship('Student', secondary=ClassRegister, backref=db.backref('classes')) def __repr__(self): return f"Class('{self.class_name}', '{self.class_starting_date}')"
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) comments = db.relationship('Comment', backref='post', lazy=True) def __repr__(self): return f"Post('{self.title}', '{self.date_posted}')"
class Exam(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) date = db.Column(db.DateTime, nullable=False) max_mark = db.Column(db.Integer, nullable=False) course_id = db.Column(db.Integer, db.ForeignKey('course.id'), nullable=False) exam_marks = db.relationship('ExamMark', backref='exam', lazy=True) def __repr__(self): return f"Exam('{self.name}', '{self.date}', '{self.topic_id}', '{self.grade_system}', '{self.max_mark}')"
class Homework(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False) due_date = db.Column(db.DateTime, nullable=False) max_mark = db.Column(db.Integer, nullable=False) topic_id = db.Column(db.Integer, db.ForeignKey('topic.id'), nullable=False) homework_marks = db.relationship('HomeworkMark', backref='homework', lazy=True) def __repr__(self): return f"Homework('{self.name}', '{self.due_date}', '{self.topic_id}', '{self.max_mark}')"