forked from StarCharlie/SRTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
148 lines (126 loc) · 4.65 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
141
142
143
144
145
146
147
148
from sqlalchemy import ForeignKey
from extension import db
# 存储所有模型
class JiuFa(db.Model):
__tablename__ = 'jiufa'
id = db.Column(db.Integer, primary_key=True, nullable=False)
leibie = db.Column(db.String(500), nullable=True)
mingcheng = db.Column(db.String(500), nullable=True)
jieshao = db.Column(db.String(500), nullable=True)
def to_dict(self):
data = {
'id': self.id,
'leibie': self.leibie,
'mingcheng': self.mingcheng,
'jieshao': self.jieshao,
}
return data
def to_search_dict(self):
data = {
'id': self.id,
'mingcheng': self.mingcheng,
'jieshao': self.jieshao,
}
return data
class BingZheng(db.Model):
__tablename__ = 'bingzheng'
id = db.Column(db.Integer, primary_key=True, nullable=False)
leibie = db.Column(db.String(500), nullable=True)
mingcheng = db.Column(db.String(500), nullable=True)
bingzheng = db.Column(db.String(500), nullable=True)
zhiliao = db.Column(db.String(500), nullable=True)
def to_dict(self):
data = {
'id': self.id,
'leibie': self.leibie,
'mingcheng': self.mingcheng,
'bingzheng': self.bingzheng,
'zhiliao': self.zhiliao,
}
return data
def to_search_dict(self):
data = {
'id': self.id,
'mingcheng': self.mingcheng,
'bingzheng': self.bingzheng,
}
return data
class XueWei(db.Model):
__tablename__ = 'xuewei'
id = db.Column(db.Integer, primary_key=True, nullable=False)
leibie = db.Column(db.String(500), nullable=True)
mingcheng = db.Column(db.String(500), nullable=True)
weizhi = db.Column(db.String(500), nullable=True)
gongxiao = db.Column(db.String(64000), nullable=True)
zhuzhi = db.Column(db.String(64000), nullable=True)
fangli = db.Column(db.String(64000), nullable=True)
cijiufa = db.Column(db.String(64000), nullable=True)
qita = db.Column(db.String(64000), nullable=True)
def to_search_dict(self):
data = {
'id': self.id,
'mingcheng': self.mingcheng,
'weizhi': self.weizhi,
}
return data
def to_dict(self):
data = {
'id': self.id,
'leibie': self.leibie,
'mingcheng': self.mingcheng,
'weizhi': self.weizhi,
'gongxiao': self.gongxiao,
'zhuzhi': self.zhuzhi,
'fangli': self.fangli,
'cijiufa': self.cijiufa,
'qita': self.qita,
}
return data
class User(db.Model):
__tablename__ = "user"
__table_args__ = {'extend_existing': True}
user_id = db.Column(db.Integer, nullable=False, primary_key=True, autoincrement=True)
user_name = db.Column(db.String(20), nullable=False)
password = db.Column(db.String(20), nullable=False)
email = db.Column(db.String(40), nullable=False)
city = db.Column(db.String(30), nullable=True)
motto = db.Column(db.String(150), nullable=True)
def to_dict(self):
"""
封装 User 对象,传递给前端只能是 json 格式,不能是实例对象
:param include_email: 只有当用户请求自己数据时,才包含 email
:return
"""
data = {
'user_id': self.user_id,
'user_name': self.user_name,
'password': self.password,
'email': self.email,
'city': self.city,
'motto': self.motto
}
return data
def from_dict(self, data, new_user=False):
"""
将前端发送过来的 json 对象转换为 User 对象
:param data:
:param new_user:
:return:
"""
for field in ['user_name', 'email']:
if field in data:
setattr(self, field, data[field])
if new_user and 'password' in data:
self.password = data['password']
class Favorites(db.Model):
__tablename__ = "favorites"
__table_args__ = {'extend_existing': True}
category = db.Column(db.Integer, nullable=False, primary_key=True)
data_id = db.Column(db.Integer, ForeignKey('thesis.thesis_id'), nullable=False, primary_key=True)
user_id = db.Column(db.Integer, ForeignKey('user.user_id'), nullable=False, primary_key=True)
class Relation(db.Model):
__tablename__ = "relation"
__table_args__ = {'extend_existing': True}
bingzheng = db.Column(db.String(20), nullable=False, primary_key=True)
jiufa = db.Column(db.String(20), nullable=False, primary_key=True)
xuewei = db.Column(db.String(20), nullable=False, primary_key=True)