📝 Update details syntax with new pymdown extensions format (#713)

This commit is contained in:
Sebastián Ramírez
2023-11-28 23:12:33 +01:00
committed by GitHub
parent be464fba69
commit 799d0aa7a6
37 changed files with 409 additions and 614 deletions

View File

@@ -8,14 +8,13 @@ We'll create data for this same **many-to-many** relationship with a link table:
We'll continue from where we left off with the previous code.
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial001.py!}
```
</details>
///
## Create Heroes
@@ -29,14 +28,13 @@ As we have done before, we'll create a function `create_heroes()` and we'll crea
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial001.py!}
```
</details>
///
This is very similar to what we have done before.
@@ -58,14 +56,13 @@ Now let's do as we have done before, `commit` the **session**, `refresh` the dat
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial001.py!}
```
</details>
///
## Add to Main
@@ -79,14 +76,13 @@ As before, add the `create_heroes()` function to the `main()` function to make s
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial001.py!}
```
</details>
///
## Run the Program

View File

@@ -18,14 +18,13 @@ We can create it just as any other **SQLModel**:
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial001.py!}
```
</details>
///
This is a **SQLModel** class model table like any other.
@@ -47,14 +46,13 @@ Let's see the `Team` model, it's almost identical as before, but with a little c
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial001.py!}
```
</details>
///
The **relationship attribute `heroes`** is still a list of heroes, annotated as `List["Hero"]`. Again, we use `"Hero"` in quotes because we haven't declared that class yet by this point in the code (but as you know, editors and **SQLModel** understand that).
@@ -76,14 +74,13 @@ Let's see the other side, here's the `Hero` model:
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial001.py!}
```
</details>
///
We **removed** the previous `team_id` field (column) because now the relationship is done via the link table. 🔥
@@ -109,14 +106,13 @@ The same as before, we will have the rest of the code to create the **engine**,
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial001.py!}
```
</details>
///
And as in previous examples, we will add that function to a function `main()`, and we will call that `main()` function in the main block:
@@ -130,14 +126,13 @@ And as in previous examples, we will add that function to a function `main()`, a
{!./docs_src/tutorial/many_to_many/tutorial001.py[ln:83-84]!}
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial001.py!}
```
</details>
///
## Run the Code

View File

@@ -40,14 +40,13 @@ And we will also add two **relationship attributes**, for the linked `team` and
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial003.py!}
```
</details>
///
The new **relationship attributes** have their own `back_populates` pointing to new relationship attributes we will create in the `Hero` and `Team` models:
@@ -76,14 +75,13 @@ We no longer have the `heroes` relationship attribute, and instead we have the n
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial003.py!}
```
</details>
///
## Update Hero Model
@@ -99,14 +97,13 @@ We change the `teams` relationship attribute for `team_links`:
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial003.py!}
```
</details>
///
## Create Relationships
@@ -122,14 +119,13 @@ But now we create the **explicit link models** manually, pointing to their hero
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial003.py!}
```
</details>
///
We are just adding the link model instances to the session, because the link model instances are connected to the heroes and teams, they will be also automatically included in the session when we commit.
@@ -235,14 +231,13 @@ Here we do that in the `update_heroes()` function:
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial003.py!}
```
</details>
///
## Run the Program with the New Relationship
@@ -335,14 +330,13 @@ We can do that by iterating on the links:
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial003.py!}
```
</details>
///
## Run the Program with the Updated Relationships

View File

@@ -4,14 +4,13 @@ Now we'll see how to update and remove these **many-to-many** relationships.
We'll continue from where we left off with the previous code.
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial001.py!}
```
</details>
///
## Get Data to Update
@@ -33,14 +32,13 @@ And because we are now using `select()`, we also have to import it.
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial002.py!}
```
</details>
///
And of course, we have to add `update_heroes()` to our `main()` function:
@@ -50,14 +48,13 @@ And of course, we have to add `update_heroes()` to our `main()` function:
{!./docs_src/tutorial/many_to_many/tutorial002.py[ln:100-107]!}
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial002.py!}
```
</details>
///
## Add Many-to-Many Relationships
@@ -73,14 +70,13 @@ We can use the same **relationship attributes** to include `hero_spider_boy` in
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial002.py!}
```
</details>
///
/// tip
@@ -173,14 +169,13 @@ In this case, we use the method `.remove()`, that takes an item and removes it f
# Code below omitted 👇
```
<details>
<summary>👀 Full file preview</summary>
/// details | 👀 Full file preview
```Python
{!./docs_src/tutorial/many_to_many/tutorial002.py!}
```
</details>
///
And this time, just to show again that by using `back_populates` **SQLModel** (actually SQLAlchemy) takes care of connecting the models by their relationships, even though we performed the operation from the `hero_spider_boy` object (modifying `hero_spider_boy.teams`), we are adding `team_z_force` to the **session**. And we commit that, without even add `hero_spider_boy`.