forked from irixjp/openstack-sample-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
32 lines (22 loc) · 792 Bytes
/
model.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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import datetime
from db import db
class Contents(db.Model):
__tablename__ = 'contents'
id = db.Column(db.Integer, primary_key=True)
timestamp = db.Column(db.DateTime)
text = db.Column(db.String(255))
def __init__(self, timestamp, text):
self.timestamp = timestamp
self.text = text
def __repr__(self):
return '<Contents>(%s, %s, %s)' % (self.id, self.timestamp, self.text.encode('utf_8'))
def get_content_all():
return Contents.query.order_by(Contents.timestamp.desc()).all()
def add_content(text):
db.session.add(Contents(datetime.datetime.now(), text))
db.session.commit()
def del_content(id):
db.session.delete(db.session.query(Contents).get(id))
db.session.commit()