diff options
3 files changed, 130 insertions, 2 deletions
diff --git a/examples/tutorials/finance_manager/part2/doc/part2.md b/examples/tutorials/finance_manager/part2/doc/part2.md new file mode 100644 index 000000000..1454d2356 --- /dev/null +++ b/examples/tutorials/finance_manager/part2/doc/part2.md @@ -0,0 +1,11 @@ +# Finance Manager Example - Part 2 + +This example represents the part two of the tutorial series on creating a simple Finance Manager +that allows users to manage their expenses and visualize them using a pie chart, using PySide6, +[SQLAlchemy], [FastAPI], and [Pydantic]. + +For more details, see the [Finance Manager Tutorial - Part 2](tutorial_financemanager_parttwo). + +[SQLalchemy]: https://www.sqlalchemy.org/ +[FastApi]: https://fastapi.tiangolo.com/ +[PyDantic]: https://pydantic-docs.helpmanual.io/ diff --git a/sources/pyside6/doc/tutorials/finance_manager/index.md b/sources/pyside6/doc/tutorials/finance_manager/index.md index 6170fc37a..6a2afc6fa 100644 --- a/sources/pyside6/doc/tutorials/finance_manager/index.md +++ b/sources/pyside6/doc/tutorials/finance_manager/index.md @@ -11,7 +11,6 @@ basics of PySide6 and QtQuick, then integrates SQLite for database management us [SQLAlchemy], and finally incorporates [FastAPI] and [Pydantic] for server-side operations and REST API integration. - ### Part 1: Building a Complete PySide6 QtQuick Application - **Introduction**: Overview of the tutorial series and prerequisites. - **Project Setup**: Setting up the development environment and installing necessary packages. @@ -26,6 +25,7 @@ REST API integration. - **Creating Database Models**: Defining database models for finance data. - **CRUD Operations**: Implementing part of the CRUD operations through Create, and Read operations and connecting them to the PySide6 application. +- For more details, see {ref}`tutorial_financemanager_parttwo`. ### Part 3: Using FastAPI and Pydantic for Server-Side Operations - **Setting Up FastAPI**: Installing FastAPI and Uvicorn, and creating a basic FastAPI application. @@ -34,7 +34,7 @@ REST API integration. - **Connecting FastAPI with PySide6**: Making HTTP requests from the PySide6 application and displaying data fetched from the API in the UI. -Each parts ends with instruction on how to deploy the application using {ref}`pyside6-deploy`. +Each part ends with instructions on how to deploy the application using {ref}`pyside6-deploy`. This structured approach ensures that readers can follow along and understand each concept before moving on to the next one, resulting in a robust and scalable finance manager application. @@ -47,3 +47,4 @@ moving on to the next one, resulting in a robust and scalable finance manager ap :hidden: part1/part1.md +part2/part2.md diff --git a/sources/pyside6/doc/tutorials/finance_manager/part2/part2.md b/sources/pyside6/doc/tutorials/finance_manager/part2/part2.md new file mode 100644 index 000000000..d8de3a4a4 --- /dev/null +++ b/sources/pyside6/doc/tutorials/finance_manager/part2/part2.md @@ -0,0 +1,116 @@ +(tutorial_financemanager_parttwo)= + +# Finance Manager Tutorial - Part 2 + +In this part of the tutorial, we will extend our finance manager app to store the expenses in a +SQLite database using the [SQLAlchemy] Python package. This will allow us to +persist the data and retrieve it even after the application is closed. + +To download the complete source code for this tutorial, visit +{ref}`example_tutorials_finance_manager_part2`. + +## Prerequisites + +Before we begin, make sure you have [SQLAlchemy] installed within your Python environment. + +You can install it using pip: + +```bash +pip install sqlalchemy +``` + +## Project Structure + +The overall project structure is the same as in the [previous part](tutorial_financemanager_partone) +of the tutorial. + +## Let's Get Started! + +### Creating the Database + +The first step is to create a `database.py` that takes care of creating and initializing the +database. This Python code will define the database schema and provide a session object to interact +with the database. The database is initialized with a single table named `finances` with the same +initial data we used in the [part one](tutorial_financemanager_partone) of the tutorial. + +<details> +<summary class="prominent-summary">database.py</summary> + +```{literalinclude} ../../../../../../../../../examples/tutorials/finance_manager/part2/database.py +--- +language: python +caption: database.py +linenos: true +--- +``` +</details> + +> Note: The database called `finances.db` will be created in the directory specified by the +`FINANCE_MANAGER_DB_PATH` environment variable if it is set. If the environment variable is not set, +the database will be created in the appropriate application data directory based on the operating +system. + +### Updating the FinanceModel Class + +Next, we need to update the FinanceModel class to interact with the database. + +In `financemodel.py`, make the following highlighted changes to load the existing expenses from the +database into the model, and also save new expenses to the database. + +<details> +<summary class="prominent-summary">financemodel.py</summary> + +```{literalinclude} ../../../../../../../../../examples/tutorials/finance_manager/part2/financemodel.py +--- +language: python +caption: Finance model class definition +linenos: true +emphasize-lines: 12, 40-50, 93-101 +--- +``` + +## Updating the Main Application + +Finally, we need to update the `main.py` file to initialize the database and use the `FinanceModel` + +<details> +<summary class="prominent-summary">main.py</summary> + +```{literalinclude} ../../../../../../../../../examples/tutorials/finance_manager/part2/main.py +--- +language: python +caption: main.py +linenos: true +emphasize-lines: 11, 15 +--- +``` +</details> + +The rest of the code remains the same as in the previous part of the tutorial. + +### Running the Application + +To run the application, execute the `main.py` file using Python: + +```bash +python main.py +``` + +### Deploying the Application + +To deploy the application, follow the same steps as in the +[previous part](tutorial_financemanager_partone) of the tutorial. + +## Summary + +In this part of the tutorial, we have extended the finance manager app by integrating a database +using [SQLAlchemy]. This allows us to store the expenses and retrieve them even after the +application is closed. + +In the next part of the tutorial, we will continue to enhance the application by using +[FastApi] and [PyDantic] to create a REST API for the finance manager app, and move the +database to a separate server. + +[SQLalchemy]: https://www.sqlalchemy.org/ +[FastApi]: https://fastapi.tiangolo.com/ +[PyDantic]: https://pydantic-docs.helpmanual.io/ |
