forked from songron/weblog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.py
143 lines (104 loc) · 4.36 KB
/
data.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
#coding=utf8
from flask.ext.sqlalchemy import SQLAlchemy
from datetime import datetime
from myapp import app
class nullpool_SQLAlchemy(SQLAlchemy):
def apply_driver_hacks(self, app, info, options):
super(nullpool_SQLAlchemy, self).apply_driver_hacks(app,info,options)
from sqlalchemy.pool import NullPool
options['poolclass'] = NullPool
del options['pool_size']
db = nullpool_SQLAlchemy(app)
class Fragment(db.Model):
__tablename__ = 'rxs_whoop_fragment'
id = db.Column(db.Integer, primary_key=True)
author = db.Column(db.String(20))
content = db.Column(db.String(1024))
pub_date = db.Column(db.DateTime)
def __init__(self, author, content):
self.author = author
self.content = content
self.pub_date = datetime.utcnow()
# -- Model For Blog --
class Category( db.Model ):
id = db.Column( db.Integer, primary_key=True)
name = db.Column( db.String(50), unique=True)
def __unicode__(self):
return self.name
article_tags = db.Table('tags',
db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')),
db.Column('article_id', db.Integer, db.ForeignKey('article.id')),
)
class Tag( db.Model ):
id = db.Column( db.Integer, primary_key=True)
name = db.Column( db.String(50), unique=True)
def __unicode__(self):
return self.name
class Article( db.Model ):
id = db.Column( db.Integer, primary_key=True)
title = db.Column( db.String(100))
content = db.Column( db.Text)
status = db.Column( db.Integer, default=1) #0, 草稿、1, 完成、-1, 失效
created_time = db.Column( db.DateTime, default=datetime.now)
modified_time = db.Column( db.DateTime, default=datetime.now)
is_always_above = db.Column( db.Integer, default=0) #置顶 0,1
share = db.Column( db.Integer, default=0) #分享到社交网络
click_count = db.Column( db.Integer, default=0)
category_id = db.Column( db.Integer, db.ForeignKey('category.id'))
category = db.relationship( 'Category', backref=db.backref('articles',lazy='dynamic'), lazy='select')
author_id = db.Column( db.Integer, db.ForeignKey('user.id'), default=1)
author = db.relationship( 'User', backref='articles', lazy='select')
tags = db.relationship( 'Tag', secondary=article_tags, backref=db.backref('articles',lazy='dynamic'))
def __unicode__(self):
return self.title
class Comment( db.Model ):
id = db.Column( db.Integer, primary_key=True)
username = db.Column( db.String(50))
email_address = db.Column( db.String(80))
site = db.Column( db.String(100))
avatar = db.Column( db.String(100)) #头像
content = db.Column( db.Text)
post_date = db.Column( db.DateTime, default=datetime.now)
visible = db.Column( db.Integer, default=1) #是否展示
ip = db.Column( db.String(15))
reply_to_comment_id = db.Column( db.Integer, db.ForeignKey('comment.id'))
reply_to_comment = db.relationship( 'Comment', backref='comments', remote_side=[id])
article_id = db.Column( db.Integer, db.ForeignKey('article.id'))
article = db.relationship( 'Article', backref=db.backref('comments',lazy='dynamic') )
def __unicode__(self):
return self.content
class User( db.Model ):
id = db.Column( db.Integer, primary_key=True)
#social account
uid = db.Column( db.BigInteger)
name = db.Column( db.String(50))
avatar = db.Column( db.String(100))
token = db.Column( db.String(80))
login_type = db.Column( db.Integer) #1:weibo;
def __unicode__(self):
return self.name
class Link( db.Model ):
id = db.Column( db.Integer, primary_key=True)
name = db.Column( db.String(50))
site = db.Column( db.String(100)) #url
def __unicode__(self):
return self.name
class BlackList( db.Model ):
id = db.Column( db.Integer, primary_key=True)
ip_address = db.Column( db.String(15))
def __unicode__(self):
return self.ip_address
class Subscriber( db.Model ):
id = db.Column( db.Integer, primary_key=True)
username = db.Column( db.String(50))
email_address = db.Column( db.String(80))
subscrible_time = db.Column( db.DateTime, default=datetime.now)
enabled = db.Column( db.Integer, default=True)
def __unicode__(self):
return self.username
# -- Data Operation --
class Data( object ):
def create_all(self):
db.create_all()
if __name__ == '__main__':
db.create_all()