July 2019
Beginner to intermediate
302 pages
9h 38m
English
If you recall, the Product model looks like the following lines of code in the models.py file:
class Product(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255))
price = db.Column(db.Float)
category_id = db.Column(db.Integer, db.ForeignKey('category.id'))
category = db.relationship(
'Category', backref=db.backref('products', lazy='dynamic')
)
First, we will create a ProductForm class in models.py; this will subclass the FlaskForm class, which is provided by flask_wtf, to represent the fields required on a webform:
from flask_wtf import FlaskForm from wtforms import StringField, DecimalField, SelectField class ProductForm(FlaskForm): name = StringField('Name') price = DecimalField('Price') ...