-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmodels.py
54 lines (42 loc) · 1.86 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
from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, Table
from sqlalchemy.orm import relationship
from database import Base
question_voter = Table(
'question_voter',
Base.metadata,
Column('user_id', Integer, ForeignKey('user.id'), primary_key=True),
Column('question_id', Integer, ForeignKey('question.id'), primary_key=True)
)
answer_voter = Table(
'answer_voter',
Base.metadata,
Column('user_id', Integer, ForeignKey('user.id'), primary_key=True),
Column('answer_id', Integer, ForeignKey('answer.id'), primary_key=True)
)
class Question(Base):
__tablename__ = "question"
id = Column(Integer, primary_key=True)
subject = Column(String, nullable=False)
content = Column(Text, nullable=False)
create_date = Column(DateTime, nullable=False)
user_id = Column(Integer, ForeignKey("user.id"), nullable=True)
user = relationship("User", backref="question_users")
modify_date = Column(DateTime, nullable=True)
voter = relationship('User', secondary=question_voter, backref='question_voters')
class Answer(Base):
__tablename__ = "answer"
id = Column(Integer, primary_key=True)
content = Column(Text, nullable=False)
create_date = Column(DateTime, nullable=False)
question_id = Column(Integer, ForeignKey("question.id"))
question = relationship("Question", backref="answers")
user_id = Column(Integer, ForeignKey("user.id"), nullable=True)
user = relationship("User", backref="answer_users")
modify_date = Column(DateTime, nullable=True)
voter = relationship('User', secondary=answer_voter, backref='answer_voters')
class User(Base):
__tablename__ = "user"
id = Column(Integer, primary_key=True)
username = Column(String, unique=True, nullable=False)
password = Column(String, nullable=False)
email = Column(String, unique=True, nullable=False)