-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
33 lines (25 loc) · 916 Bytes
/
models.py
File metadata and controls
33 lines (25 loc) · 916 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
"""Models for Cupcake app."""
from flask import app
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
def connect_db(app):
db.app = app
db.init_app(app)
class Cupcake(db.Model):
""" cupcake model """
__tablename__ = 'cupcakes'
id = db.Column(db.Integer,primary_key=True, autoincrement=True)
flavor = db.Column(db.Text, nullable=False)
size = db.Column(db.Text, nullable=False)
rating = db.Column(db.Float, nullable=False)
image = db.Column(db.Text, nullable=False, default='https://tinyurl.com/demo-cupcake')
def serialize(self):
return {
'id': self.id,
'flavor': self.flavor,
'size': self.size,
'rating': self.rating,
'image': self.image
}
def __repr__(self):
return f'<Cupcake {self.id}, flavor:{self.flavor}, size:{self.size}, rating:{self.rating}, image:{self.image}>'