-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
43 lines (36 loc) · 1.67 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
#模型
from exts import db
from datetime import datetime
class UserModel(db.Model):
__tablename__ = 'user'
id = db.Column(db.Integer,primary_key=True,autoincrement=True)
username = db.Column(db.String(100),nullable=False)
password = db.Column(db.String(200), nullable=False)
email = db.Column(db.String(100), nullable=False,unique=True)
join_time = db.Column(db.DateTime, default=datetime.now)
class EmailCaptchaModel(db.Model):
__tablename__ = 'email_captcha'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
email = db.Column(db.String(100), nullable=False)
captcha = db.Column(db.String(100),nullable=False)
class ShareModel(db.Model):
__tablename__ = 'share'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
title = db.Column(db.String(100),nullable=False)
image_path = db.Column(db.String(200), nullable=False)
content = db.Column(db.Text, nullable=False)
create_time = db.Column(db.DateTime, default=datetime.now)
#外键
author_id = db.Column(db.Integer, db.ForeignKey("user.id"))
author = db.relationship(UserModel, backref="shares")
class CommentModel(db.Model):
__tablename__ = 'comment'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
content = db.Column(db.Text, nullable=False)
create_time = db.Column(db.DateTime, default=datetime.now)
#外键
share_id = db.Column(db.Integer, db.ForeignKey("share.id"))
author_id = db.Column(db.Integer, db.ForeignKey("user.id"))
#关系
share = db.relationship(ShareModel, backref=db.backref("comments", order_by=create_time.desc()))
author = db.relationship(UserModel, backref="comment")