📝 Update markdown includes format (#1254)

This commit is contained in:
Sebastián Ramírez
2024-12-22 14:30:05 +00:00
committed by GitHub
parent 0c65fed61b
commit 5100200bea
39 changed files with 213 additions and 10659 deletions

View File

@@ -38,69 +38,7 @@ The `Hero` table model will now store a new field `hashed_password`.
And the data models for `HeroCreate` and `HeroUpdate` will also have a new field `password` that will contain the plain text password sent by clients.
//// tab | Python 3.10+
```Python hl_lines="11 15 26"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py[ln:5-28]!}
# Code below omitted 👇
```
////
//// tab | Python 3.9+
```Python hl_lines="11 15 26"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py[ln:7-30]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="11 15 26"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002.py[ln:7-30]!}
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py!}
```
////
//// tab | Python 3.9+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002.py!}
```
////
///
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[5:28] hl[13,17,28] *}
When a client is creating a new hero, they will send the `password` in the request body.
@@ -112,81 +50,7 @@ The app will receive the data from the client using the `HeroCreate` model.
This contains the `password` field with the plain text password, and we cannot use that one. So we need to generate a hash from it.
//// tab | Python 3.10+
```Python hl_lines="11"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py[ln:42-44]!}
# Code here omitted 👈
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py[ln:55-57]!}
# Code below omitted 👇
```
////
//// tab | Python 3.9+
```Python hl_lines="11"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py[ln:44-46]!}
# Code here omitted 👈
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py[ln:57-59]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="11"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002.py[ln:44-46]!}
# Code here omitted 👈
{!./docs_src/tutorial/fastapi/update/tutorial002.py[ln:57-59]!}
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py!}
```
////
//// tab | Python 3.9+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002.py!}
```
////
///
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[42:44,55:57] hl[57] *}
## Create an Object with Extra Data
@@ -242,69 +106,7 @@ So now, `db_user_dict` has the updated `age` field with `32` instead of `None` a
Similar to how dictionaries have an `update` method, **SQLModel** models have a parameter `update` in `Hero.model_validate()` that takes a dictionary with extra data, or data that should take precedence:
//// tab | Python 3.10+
```Python hl_lines="8"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py[ln:55-64]!}
# Code below omitted 👇
```
////
//// tab | Python 3.9+
```Python hl_lines="8"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py[ln:57-66]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="8"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002.py[ln:57-66]!}
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py!}
```
////
//// tab | Python 3.9+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002.py!}
```
////
///
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[55:64] hl[60] *}
Now, `db_hero` (which is a *table model* `Hero`) will extract its values from `hero` (which is a *data model* `HeroCreate`), and then it will **`update`** its values with the extra data from the dictionary `extra_data`.
@@ -318,69 +120,7 @@ Now let's say we want to **update a hero** that already exists in the database.
The same way as before, to avoid removing existing data, we will use `exclude_unset=True` when calling `hero.model_dump()`, to get a dictionary with only the data sent by the client.
//// tab | Python 3.10+
```Python hl_lines="9"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py[ln:83-89]!}
# Code below omitted 👇
```
////
//// tab | Python 3.9+
```Python hl_lines="9"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py[ln:85-91]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="9"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002.py[ln:85-91]!}
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py!}
```
////
//// tab | Python 3.9+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002.py!}
```
////
///
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[83:89] hl[89] *}
Now, this `hero_data` dictionary could contain a `password`. We need to check it, and if it's there, we need to generate the `hashed_password`.
@@ -390,69 +130,7 @@ And then we can update the `db_hero` object using the method `db_hero.sqlmodel_u
It takes a model object or dictionary with the data to update the object and also an **additional `update` argument** with extra data.
//// tab | Python 3.10+
```Python hl_lines="15"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py[ln:83-99]!}
# Code below omitted 👇
```
////
//// tab | Python 3.9+
```Python hl_lines="15"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py[ln:85-101]!}
# Code below omitted 👇
```
////
//// tab | Python 3.7+
```Python hl_lines="15"
# Code above omitted 👆
{!./docs_src/tutorial/fastapi/update/tutorial002.py[ln:85-101]!}
# Code below omitted 👇
```
////
/// details | 👀 Full file preview
//// tab | Python 3.10+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py!}
```
////
//// tab | Python 3.9+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py!}
```
////
//// tab | Python 3.7+
```Python
{!./docs_src/tutorial/fastapi/update/tutorial002.py!}
```
////
///
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[83:99] hl[95] *}
/// tip