-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
75 lines (53 loc) · 1.74 KB
/
main.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
from flask import Flask
from config import DevConfig
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config.from_object(DevConfig)
db = SQLAlchemy(app)
tags = db.Table(
db.Column('post_id',db.Integer(),db.ForeignKey('post.id')),
db.Column('tag_id',db.Integer(),db.ForeignKey('tag.id'))
)
class Post(db.Model):
id = db.Column(db.Integer(),primary_key = True)
title = db.Column(db.String(255))
text = db.Column(db.Text())
publish_date = db.Column(db.DateTime())
user_id = db.Column(db.Integer(),db.ForeignKey('user.id'))
def __init__(self,title):
self.title = title
def __repr__(self):
return "<Post '{}'>".format(self.title)
class User(db.Model):
id = db.Column(db.Integer(),primary_key = True)
username = db.Column(db.String(255))
password = db.Column(db.String(255))
posts = db.relationship(
'Post',
backref = 'user',
lazy = 'dynamic'
)
def __init__(self,username):
self.username = username
def __repr__(self):
return "<User '{}'>".format(self.username)
class Comment(db.Model):
id = db.Column(db.Integer(),primary_key = True)
name = db.Column(db.String(255))
text = db.Column(db.Text())
date = db.Column(db.DateTime())
post_id = db.Column(db.Integer(),db.ForeignKey('post.id'))
def __repr__(self):
return "<Comment '{}'>".format(self.text[:15])
class Tag(db.Model):
id = db.Column(db.Integer(),primary_key=True)
title = db.Column(db.String(255))
def __init__(self,title):
self.title = title
def __repr__(self):
return "<Tag '{}'>".format(self.title)
@app.route('/')
def home():
return '<h1>Hello World!</h1>'
if __name__ == '__main__':
app.run()