-
Notifications
You must be signed in to change notification settings - Fork 2
/
models.py
140 lines (95 loc) · 4.57 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# coding: utf-8
from sqlalchemy import Column, Date, DateTime, ForeignKey, String, Text, text
from sqlalchemy.dialects.mysql import INTEGER, TINYINT
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
metadata = Base.metadata
class Course(Base):
__tablename__ = 'course'
courseName = Column(String(100), nullable=False)
courseID = Column(INTEGER(11), primary_key=True)
class QuestionType(Base):
__tablename__ = 'questionType'
questionTypeID = Column(INTEGER(11), primary_key=True)
questionTypeName = Column(String(10), nullable=False)
class Student(Base):
__tablename__ = 'student'
name = Column(String(100), nullable=False)
gender = Column(String(10), nullable=False)
age = Column(INTEGER(11))
profilePicture = Column(String(500), server_default=text("'https://www.pngitem.com/pimgs/m/41-415019_profile-man-male-free-picture-male-avatar-clipart.png'"))
studentID = Column(INTEGER(11), primary_key=True)
class Teacher(Base):
__tablename__ = 'teacher'
teacherID = Column(INTEGER(11), primary_key=True)
teacherName = Column(String(100), nullable=False)
teacherEmail = Column(String(100), nullable=False)
class Clas(Base):
__tablename__ = 'class'
classID = Column(INTEGER(11), primary_key=True)
courseID = Column(ForeignKey('course.courseID'), nullable=False, index=True)
date = Column(Date, nullable=False)
time = Column(DateTime, nullable=False)
duration = Column(INTEGER(11), nullable=False)
active = Column(TINYINT(1), nullable=False)
teacherID = Column(ForeignKey('teacher.teacherID'), nullable=False, index=True)
course = relationship('Course')
teacher = relationship('Teacher')
class CourseStudent(Base):
__tablename__ = 'course_student'
course_studentID = Column(String(10), primary_key=True)
studentID = Column(ForeignKey('student.studentID', ondelete='CASCADE'), nullable=False, index=True)
courseID = Column(ForeignKey('course.courseID', ondelete='CASCADE'), nullable=False, index=True)
course = relationship('Course')
student = relationship('Student')
class CourseTeacher(Base):
__tablename__ = 'course_teacher'
course_teacherID = Column(String(100), primary_key=True)
courseID = Column(ForeignKey('course.courseID'), nullable=False, index=True)
teacherID = Column(ForeignKey('teacher.teacherID'), nullable=False, index=True)
course = relationship('Course')
teacher = relationship('Teacher')
class Enroll(Base):
__tablename__ = 'enroll'
enrollID = Column(INTEGER(11), primary_key=True)
classID = Column(ForeignKey('class.classID'), nullable=False, index=True)
studentID = Column(ForeignKey('student.studentID'), nullable=False, index=True)
clas = relationship('Clas')
student = relationship('Student')
class Question(Base):
__tablename__ = 'question'
questionID = Column(INTEGER(11), primary_key=True)
questionTypeID = Column(ForeignKey('questionType.questionTypeID'), nullable=False, index=True)
text = Column(Text, nullable=False)
option = Column(Text)
correctOption = Column(INTEGER(11))
correctTF = Column(TINYINT(1))
classID = Column(ForeignKey('class.classID'), nullable=False, index=True)
asked = Column(TINYINT(1), nullable=False)
clas = relationship('Clas')
questionType = relationship('QuestionType')
class Score(Base):
__tablename__ = 'score'
scoreID = Column(INTEGER(11), primary_key=True)
classID = Column(ForeignKey('class.classID'), nullable=False, index=True)
studentID = Column(ForeignKey('student.studentID'), nullable=False, index=True)
totalScore = Column(INTEGER(11), nullable=False)
rank = Column(INTEGER(11))
clas = relationship('Clas')
student = relationship('Student')
class QuestionAsked(Base):
__tablename__ = 'question_asked'
questionAsked = Column(String(10), primary_key=True)
questionID = Column(ForeignKey('question.questionID'), nullable=False, index=True)
studentID = Column(ForeignKey('student.studentID'), nullable=False, index=True)
question = relationship('Question')
student = relationship('Student')
class Response(Base):
__tablename__ = 'response'
responseID = Column(INTEGER(11), primary_key=True)
questionID = Column(ForeignKey('question.questionID', ondelete='CASCADE'), nullable=False, index=True)
studentID = Column(ForeignKey('student.studentID', ondelete='CASCADE'), nullable=False, index=True)
valid = Column(TINYINT(1), nullable=False)
question = relationship('Question')
student = relationship('Student')