class Answer(db.Model): id = db.Column(db.Integer, primary_key=True) question_id = db.Column(db.Integer, db.ForeignKey('question.id'), nullable=False) choice_id = db.Column(db.Integer, db.ForeignKey('choice.id'), nullable=False) def __repr__(self): return f"Answer([{self.id}], '{self.choice_id}', [Q:{self.question_id}]')"
class Choice(db.Model): id = db.Column(db.Integer, primary_key=True) body = db.Column(db.Text, nullable=False) question_id = db.Column(db.Integer, db.ForeignKey('question.id'), nullable=False) #question = db.relationship('Question', back_populates='choices') def __repr__(self): return f"Choice([{self.id}], '{self.body}', [Q:{self.question_id}]')"
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='default.jpg') password = db.Column(db.String(60), nullable=False) user_type = db.Column(db.Integer, nullable=False) comments = db.relationship("Comment", backref="user_comments") #student_user = 1 #moderator_user = 2 #comments = db.relationship('Comment', back_populates='author') def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class Comment(db.Model): id = db.Column(db.Integer, primary_key=True) time_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) comment = db.Column(db.Text, nullable=False) edited = db.Column(db.Boolean, unique=False, default=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) user = db.relationship('User', back_populates='comments') #author = db.relationship('User', back_populates='comments') question_id = db.Column(db.Integer, db.ForeignKey('question.id'), nullable=False) # corresponds to question comment was asked on def __repr__(self): return f"Comment('{self.time_posted}', '{self.comment}')"
class Question(db.Model): id = db.Column(db.Integer, primary_key=True) body = db.Column(db.Text, nullable=False) solution_id = db.Column(db.Integer, db.ForeignKey('choice.id'), nullable=False) course_id = db.Column(db.Integer, db.ForeignKey('course.id'), nullable=False) image_file = db.Column(db.String(20), nullable=True) #unit_no = db.Column(db.Integer, nullable=False) topic_no = db.Column(db.Integer, nullable=False) # time = db.Column(db.DateTime, nullable=True) # not sure if DateTime is best type time = db.Column(db.Integer, nullable=True) #choices = db.relationship('Choice', back_populates='question') def __repr__(self): return f"Question([{self.id}], topic-{self.topic_no} '{self.body}', 'Image:{self.image_file}, [C:{self.solution_id}])"
class Course(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20), nullable=False)