flask sqlalchemy json restful

Solutions on MaxInterview for flask sqlalchemy json restful by the best coders in the world

showing results for - "flask sqlalchemy json restful"
Luca
12 Aug 2019
1from flask_sqlalchemy import SQLAlchemy
2 
3db = SQLAlchemy()
4 
5class BookModel(db.Model):
6    __tablename__ = 'books'
7 
8    id = db.Column(db.Integer, primary_key=True)
9    name = db.Column(db.String(80))
10    price = db.Column(db.Integer())
11    author = db.Column(db.String(80))
12 
13    def __init__(self, name, price, author):
14        self.name = name
15        self.price = price
16        self.author = author 
17     
18    def json(self):
19        return {"name":self.name, "price":self.price, "author":self.author}
20