models.py
2.43 KB
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
from sqlalchemy import Table, Column, ForeignKey, Integer, Float, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
# ===========================================================================
# Declare ORM
Base = declarative_base()
# ---------------------------------------------------------------------------
class Student(Base):
__tablename__ = 'students'
id = Column(String, primary_key=True)
name = Column(String)
password = Column(String)
# ---
tests = relationship('Test', back_populates='student')
questions = relationship('Question', back_populates='student')
# def __repr__(self):
# return 'Student:\n id: "{0}"\n name: "{1}"\n password: "{2}"'.format(self.id, self.name, self.password)
# ---------------------------------------------------------------------------
class Test(Base):
__tablename__ = 'tests'
id = Column(Integer, primary_key=True) # auto_increment
ref = Column(String)
grade = Column(Float)
starttime = Column(String)
finishtime = Column(String)
student_id = Column(String, ForeignKey('students.id'))
# ---
student = relationship('Student', back_populates='tests')
questions = relationship('Question', back_populates='test')
# def __repr__(self):
# return 'Test:\n id: "{0}"\n ref="{1}"\n grade="{2}"\n starttime="{3}"\n finishtime="{4}"\n student_id="{5}"'.format(self.id, self.ref, self.grade, self.starttime, self.finishtime, self.student_id)
# ---------------------------------------------------------------------------
class Question(Base):
__tablename__ = 'questions'
id = Column(Integer, primary_key=True) # auto_increment
ref = Column(String)
grade = Column(Float)
starttime = Column(String)
finishtime = Column(String)
student_id = Column(String, ForeignKey('students.id'))
test_id = Column(String, ForeignKey('tests.id'))
# ---
student = relationship('Student', back_populates='questions')
test = relationship('Test', back_populates='questions')
# def __repr__(self):
# return '''
# Question:
# id: "{0}"
# ref: "{1}"
# grade: "{2}"
# starttime: "{3}"
# finishtime: "{4}"
# student_id: "{5}"
# test_id: "{6}"
# '''.fotmat(self.id, self.ref, self.grade, self.starttime, self.finishtime, self.student_id, self.test_id)
# ---------------------------------------------------------------------------