Skip to content

Commit 7b179d5

Browse files
author
App Generator
committed
Phase 4 -Define the new Table (Model)
1 parent b7dfb93 commit 7b179d5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

app/models.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- encoding: utf-8 -*-
2+
"""
3+
Copyright (c) 2019 - present AppSeed.us
4+
"""
5+
6+
from app import db
7+
8+
class Stats(db.Model):
9+
10+
id = db.Column(db.Integer, primary_key=True )
11+
month = db.Column(db.String(64), unique=True )
12+
sold_units = db.Column(db.Integer )
13+
14+
def __init__(self, id, month, sold_units):
15+
self.id = id
16+
self.month = month
17+
self.sold_units = sold_units
18+
19+
def __repr__(self):
20+
return self.month + ' - ' + str(self.sold_units)
21+
22+
# Optional helper
23+
def save(self):
24+
25+
# inject self into db session
26+
db.session.add ( self )
27+
28+
# commit change and save the object
29+
db.session.commit( )
30+
31+
return self

0 commit comments

Comments
 (0)