Creating a basic product model
In this recipe, we will create an application that will help us store products to be displayed on the catalog section of a website. It should be possible to add products to the catalog and delete them as and when required. As we saw in previous chapters, this is possible to do using non-persistent storage as well. But, here we will store data in a database to have persistent storage.
How to do it…
The new directory layout will look as follows:
flask_catalog/
    - run.py
    my_app/
        – __init__.py
        catalog/
            - __init__.py
            - views.py
            - models.pyFirst of all, we will start by modifying our application configuration file, that is, flask_catalog/my_app/__init__.py:
from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' db = SQLAlchemy(app) from my_app.catalog.views import catalog app.register_blueprint(catalog) db.create_all...