-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
70 lines (58 loc) · 1.64 KB
/
Copy pathmodel.py
File metadata and controls
70 lines (58 loc) · 1.64 KB
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
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:root@localhost/test'
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(32), unique=True)
password = db.Column(db.String(32))
def __init__(self, username, password):
self.username = username
self.password = password
def add(self):
try:
db.session.add(self)
db.session.commit()
return self.id
except Exception, e:
db.session.rollback()
return e
finally:
return 0
def isExisted(self):
temUser = User.query.filter_by(username=self.username, password=self.password).first()
if temUser is None:
return 0
else:
return 1
class Entry(db.Model):
id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.Text)
sender = db.Column(db.String(32))
def __init__(self, content, sender):
self.content = content
self.sender = sender
def add(self):
try:
db.session.add(self)
db.session.commit()
return self.id
except Exception, e:
db.session.rollback()
return e
finally:
return 0
def getAllEntry():
Entlist = []
Entlist = Entry.query.filter_by().all()
return Entlist
def test():
db.create_all()
e = Entry("hi", "ErrareHest")
e.add()
l = getAllEntry()
for each in l:
print each
if __name__ == '__main__':
test()