class Student(db.Model): id = db.Column(db.Integer, primary_key = True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) submitted_assignment = db.relationship('Assignment', secondary = 'submits_assign', backref = db.backref('submitted_by', lazy = 'dynamic')) submitted_quiz = db.relationship('Quiz', secondary = 'submits_quiz', backref = db.backref('submitted_by', lazy = 'dynamic'))
class Teacher(db.Model): id = db.Column(db.Integer, primary_key = True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) assignment_created = db.relationship('Assignment', backref = 'created_by') quiz_created = db.relationship('Quiz', backref = 'created_by') students = db.relationship('Student', secondary = 'teaches', backref = db.backref('taught_by', lazy = 'dynamic'))
class Quiz(db.Model): id = db.Column(db.Integer, primary_key = True) title = db.Column(db.String(30), nullable = False) start_time = db.Column(db.DateTime, nullable = False) end_time = db.Column(db.DateTime, nullable = False) active = db.Column(db.Boolean, nullable = False, default = False) time_created = db.Column(db.DateTime, nullable = False, default = datetime.now) teacher_id = db.Column(db.Integer, db.ForeignKey('teacher.id')) marks = db.Column(db.Integer) questions = db.relationship('Quiz_Questions', backref = 'quiz')
class User(db.Model,UserMixin): id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(20), nullable = False) email = db.Column(db.String(50), unique = True, nullable = False) password = db.Column(db.String(50), nullable = False) verified = db.Column(db.Boolean, nullable = False, default = False) student = db.relationship('Student', backref = 'user', uselist = False) teacher = db.relationship('Teacher', backref = 'user', uselist = False) def get_reset_token(self,expire_sec = 600): s = Serializer(current_app.config["SECRET_KEY"],expire_sec) return s.dumps({"user_id": self.id}).decode("utf-8") def verify_reset_token(token): s = Serializer(current_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.id}, {self.name}, {self.email}, {self.password}"