-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
96 lines (78 loc) · 3.61 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
from exts import db
from flask_login import UserMixin
# 书
class Book(db.Model):
__tablename__ = 'books'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
bookname = db.Column(db.String(100), nullable=False) # 书名
detail = db.Column(db.Text) # 详细介绍
price = db.Column(db.Float, nullable=False) # 单价
sales = db.Column(db.Integer, nullable=False) # 销量
seller_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False) # 卖家id,外键
state = db.Column(db.String(100), nullable=False) # 书本状态
# 书本状态:正在卖; 已下架
tag = db.Column(db.String(100)) # 标签
image = db.Column(db.LargeBinary(length=65536)) # 照片
qrcode = db.Column(db.LargeBinary(length=65536), nullable=False) # 付款码
file = db.Column(db.Text, nullable=False) # 文件的磁力链接
# 用户
class User(db.Model, UserMixin):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
username = db.Column(db.String(100), nullable=False, unique=True) # 用户名
password = db.Column(db.Text, nullable=False) # 密码
moreinfo = db.Column(db.Text) # 更多信息
def __init__(self, id=None, username=None, password=None, moreinfo=None):
self.id = id
self.username = username
self.password = password
self.moreinfo = moreinfo
def get_id(self):
return str(self.id)
# 管理员
class Administrator(db.Model, UserMixin):
__tablename__ = 'administrators'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
username = db.Column(db.String(100), nullable=False, unique=True) # 用户名
password = db.Column(db.Text, nullable=False) # 密码
def __init__(self, id=None, username=None, password=None):
self.id = id
self.username = username
self.password = password
def get_id(self):
return str(self.id)
# 订单
class Order(db.Model):
__tablename__ = 'orders'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
seller_id = db.Column(db.Integer, nullable=False) # 卖家id
buyer_id = db.Column(db.Integer, nullable=False) # 买家id
book_id = db.Column(db.Integer, nullable=False) # 书籍id
state = db.Column(db.String(100), nullable=False) # 订单状态
# 订单状态:收藏; 已购买
file = db.Column(db.Text, nullable=False) # 文件的磁力链接
# 留言
class Message(db.Model):
__tablename__ = 'messages'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
user_id = db.Column(db.Integer, nullable=False) # 用户id
username = db.Column(db.String(100), nullable=False) # 用户名
text = db.Column(db.Text, nullable=False)
# 评论
class Comment(db.Model):
__tablename__ = 'comments'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
user_id = db.Column(db.Integer, nullable=False) # 用户id
username = db.Column(db.String(100), nullable=False) # 用户名
book_id = db.Column(db.Integer, nullable=False) # 书籍id
bookname = db.Column(db.String(100), nullable=False) # 书籍名
text = db.Column(db.Text, nullable=False)
# 举报
class Report(db.Model):
__tablename__ = 'reports'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
user_id = db.Column(db.Integer, nullable=False) # 用户id
username = db.Column(db.String(100), nullable=False) # 用户名
book_id = db.Column(db.Integer, nullable=False) # 书籍id
bookname = db.Column(db.String(100), nullable=False) # 书籍名
text = db.Column(db.Text, nullable=False)