-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
75 lines (56 loc) · 3.23 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
class Topic(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(256), nullable=True)
questions = db.relationship("Question", back_populates="topic")
class Question(db.Model):
id = db.Column(db.Integer, primary_key=True)
topic_id = db.Column(db.Integer, db.ForeignKey("topic.id", ondelete="SET NULL"))
question_text = db.Column(db.String(256), nullable=False)
image_src = db.Column(db.String(256), nullable=True)
topic = db.relationship("Topic", back_populates="questions")
quizzes = db.relationship("Quiz", secondary=quiz_questions, back_populates="questions")
answers = db.relationship("Answer", cascade="all, delete-orphan", back_populates="question")
comments = db.relationship("Comment", cascade="all, delete-orphan", back_populates="question")
class Answer(db.Model):
id = db.Column(db.Integer, primary_key=True)
question_id = db.Column(db.Integer, db.ForeignKey("question.id", ondelete="CASCADE"))
answer_text = db.Column(db.String(256), nullable=False)
explanation_text = db.Column(db.String(256), nullable=True)
is_correct = db.Column(db.Integer, nullable=False) # Boolean value 1 or 0
question = db.relationship("Question", back_populates="answers")
class Comment(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="SET NULL"), nullable=True)
question_id = db.Column(db.Integer, db.ForeignKey("question.id", ondelete="CASCADE"), nullable=False)
comment_text = db.Column(db.String(256), nullable=False)
user = db.relationship("User", back_populates="comments")
question = db.relationship("Question", back_populates="comments")
"""
from app import db
from datetime import datetime
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(256), unique=True, nullable=False)
email = db.Column(db.String(256), nullable=False)
pw_hash = db.Column(db.String(256), nullable=False)
sessions = db.relationship("Session", back_populates="user")
samples = db.relationship("Sample", back_populates="user")
class Session(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="SET NULL"), nullable=True)
created = db.Column(db.DateTime, nullable=False)
completed = db.Column(db.DateTime, nullable=True)
result = db.Column(db.String(256), nullable=True)
number_of_samples = db.Column(db.Integer, nullable=False)
user = db.relationship("User", back_populates="sessions")
samples = db.relationship("Sample", back_populates="session")
class Sample(db.Model):
id = db.Column(db.Integer, primary_key=True)
added_by = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="SET NULL"), nullable=True)
is_correct = db.Column(db.Integer, nullable=False) # Boolean value 1 or 0
session_id = db.Column(db.Integer, db.ForeignKey("session.id", ondelete="SET NULL"), nullable=True)
number_in_session = db.Column(db.Integer, nullable=True)
dog_answer = db.Column(db.String(144), nullable=True)
session = db.relationship("Session", back_populates="samples")
user = db.relationship("User", back_populates="samples")