Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Create Models | Database and Models
Professional Web API with Flask
course content

Зміст курсу

Professional Web API with Flask

Professional Web API with Flask

1. Introduction to the Course
2. Database and Models
3. Flask-Smorest and Schemas
4. Endpoints with Blueprints and MethodView
5. Authentication with JWT
6. Deployment

book
Create Models

As we embark on creating a professional application, it's crucial to organize functionality and logic across various packages and files. This methodology not only aids in maintaining a clean codebase but also in simplifying the development process. We have already initiated this structure by segregating the database initialization in db.py and the application launch and configuration settings in app.py.

Creating the Models Package

To further our application's organization, we will now create a new Python package named models. If your IDE allows only folder creation, simply create a folder and include an empty __init__.py file in it to signify it as a package. Within this package, we will create several files for our models: team.py, player.py, user.py, and club.py.

Example Model Creation: Team

Here, I'll remind you how to create models using team.py as an example:

This pattern is repeated for the player and club models.

Player Model:

Club Model:

User Model:

Simplifying Model Imports

To ease the importation of models within our application, we'll declare them in the __init__.py file of the models package:

This organization not only streamlines the development process by segregating the database schema into understandable chunks but also facilitates easier management and modification of the application structure. By adopting this modular approach, we ensure that our application remains scalable and maintainable, accommodating future expansions and modifications with ease.

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 2
We're sorry to hear that something went wrong. What happened?
some-alt