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

Зміст курсу

Professional Web API with Flask

Create ModelsCreate 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
course content

Зміст курсу

Professional Web API with Flask

Create ModelsCreate 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
some-alt