Creating models with their relationships

Now, we will create the models that we will use to represent and persist the notification categories, notifications, and their relationships in the PostgreSQL database.

Open the service/models.py file and replace its contents with the following code. The lines that declare fields related to other models are highlighted in the code listing. If you created a new virtual environment, create a new models.py file within the service folder. The code file for the sample is included in the restful_python_2_02_01 folder, in the Flask01/service/models.py file:

from marshmallow import Schema, fields, pre_load from marshmallow import validate from flask_sqlalchemy import SQLAlchemy from flask_marshmallow import ...

Get Hands-On RESTful Python Web Services - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.