-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
34 lines (27 loc) · 883 Bytes
/
model.py
File metadata and controls
34 lines (27 loc) · 883 Bytes
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
#!/usr/bin/env python
import json
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///plantdata.db'
db = SQLAlchemy(app)
def add(item):
db.session.add(item)
def save_all():
db.session.commit()
# common_name, plant_type, scientific_name, helps, helped_by,
# attracts, repels, avoid, comment
class Plants(db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(50), nullable = False)
friend = db.Column(db.String(500), nullable=True)
avoid = db.Column(db.String(500), nullable=True)
def __init__(self, name, friend, avoid):
self.name = name
self.friend = json.dumps(friend)
self.avoid = json.dumps(avoid)
@property
def serialize(self):
return {'id': self.id,
'name': self.name,
}