Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝Update includes in docs/tutorial/fastapi/relationships.md #1176

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
307 changes: 13 additions & 294 deletions docs/tutorial/fastapi/relationships.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,185 +44,29 @@ It's because we declared the `HeroPublic` with only the same base fields of the

And the same way, we declared the `TeamPublic` with only the same base fields of the `TeamBase` plus the `id`. But it doesn't include a field `heroes` for the **relationship attribute**.

//// tab | Python 3.10+
{* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py ln[5:7] hl[3:5,9:10,23:24] *}

```Python hl_lines="3-5 9-10 14-19 23-24"
# Code above omitted 👆
{* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py ln[20:21] hl[3:5,9:10,23:24] *}

{!./docs_src/tutorial/fastapi/teams/tutorial001_py310.py[ln:5-7]!}
{* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py ln[29:34] hl[3:5,9:10,23:24] *}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/teams/tutorial001_py310.py[ln:20-21]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/teams/tutorial001_py310.py[ln:29-34]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/teams/tutorial001_py310.py[ln:43-44]!}

# Code below omitted 👇
```

////

//// tab | Python 3.9+

```Python hl_lines="3-5 9-10 14-19 23-24"
# Code above omitted 👆

{!./docs_src/tutorial/fastapi/teams/tutorial001_py39.py[ln:7-9]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/teams/tutorial001_py39.py[ln:22-23]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/teams/tutorial001_py39.py[ln:31-36]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/teams/tutorial001_py39.py[ln:45-46]!}

# Code below omitted 👇
```

////

//// tab | Python 3.7+

```Python hl_lines="3-5 9-10 14-19 23-24"
# Code above omitted 👆

{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:7-9]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:22-23]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:31-36]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:45-46]!}

# Code below omitted 👇
```

////
{* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py ln[43:44] hl[3:5,9:10,23:24] *}

/// details | 👀 Full file preview

//// tab | Python 3.10+

```Python
{!./docs_src/tutorial/fastapi/teams/tutorial001_py310.py!}
```

////

//// tab | Python 3.9+

```Python
{!./docs_src/tutorial/fastapi/teams/tutorial001_py39.py!}
```

////

//// tab | Python 3.7+

```Python
{!./docs_src/tutorial/fastapi/teams/tutorial001.py!}
```

////

///
{* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py *}

Now, remember that <a href="https://fastapi.tiangolo.com/tutorial/response-model/" class="external-link" target="_blank">FastAPI uses the `response_model` to validate and **filter** the response data</a>?

In this case, we used `response_model=TeamPublic` and `response_model=HeroPublic`, so FastAPI will use them to filter the response data, even if we return a **table model** that includes **relationship attributes**:

//// tab | Python 3.10+

```Python hl_lines="3 8 12 17"
# Code above omitted 👆

{!./docs_src/tutorial/fastapi/teams/tutorial001_py310.py[ln:102-107]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/teams/tutorial001_py310.py[ln:156-161]!}

# Code below omitted 👇
```

////

//// tab | Python 3.9+

```Python hl_lines="3 8 12 17"
# Code above omitted 👆
{* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py ln[102:107] hl[3,8,12,17] *}

{!./docs_src/tutorial/fastapi/teams/tutorial001_py39.py[ln:104-109]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/teams/tutorial001_py39.py[ln:158-163]!}

# Code below omitted 👇
```

////

//// tab | Python 3.7+

```Python hl_lines="3 8 12 17"
# Code above omitted 👆

{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:104-109]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/teams/tutorial001.py[ln:158-163]!}

# Code below omitted 👇
```

////
{* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py ln[156:161] hl[3,8,12,17] *}

/// details | 👀 Full file preview

//// tab | Python 3.10+

```Python
{!./docs_src/tutorial/fastapi/teams/tutorial001_py310.py!}
```

////

//// tab | Python 3.9+

```Python
{!./docs_src/tutorial/fastapi/teams/tutorial001_py39.py!}
```

////

//// tab | Python 3.7+

```Python
{!./docs_src/tutorial/fastapi/teams/tutorial001.py!}
```

////

///
{* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py *}

## Don't Include All the Data

Expand Down Expand Up @@ -304,69 +148,12 @@ Let's add the models `HeroPublicWithTeam` and `TeamPublicWithHeroes`.

We'll add them **after** the other models so that we can easily reference the previous models.

//// tab | Python 3.10+

```Python hl_lines="3-4 7-8"
# Code above omitted 👆

{!./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py[ln:59-64]!}

# Code below omitted 👇
```

////

//// tab | Python 3.9+

```Python hl_lines="3-4 7-8"
# Code above omitted 👆

{!./docs_src/tutorial/fastapi/relationships/tutorial001_py39.py[ln:61-66]!}

# Code below omitted 👇
```

////

//// tab | Python 3.7+

```Python hl_lines="3-4 7-8"
# Code above omitted 👆

{!./docs_src/tutorial/fastapi/relationships/tutorial001.py[ln:61-66]!}

# Code below omitted 👇
```

////
{* ./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py ln[59:64] hl[3:4,7:8] *}

/// details | 👀 Full file preview

//// tab | Python 3.10+

```Python
{!./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py!}
```

////

//// tab | Python 3.9+

```Python
{!./docs_src/tutorial/fastapi/relationships/tutorial001_py39.py!}
```

////

//// tab | Python 3.7+

```Python
{!./docs_src/tutorial/fastapi/relationships/tutorial001.py!}
```

////
{* ./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py *}

///

These two models are very **simple in code**, but there's a lot happening here. Let's check it out.

Expand Down Expand Up @@ -400,81 +187,13 @@ This will tell **FastAPI** to take the object that we return from the *path oper

In the case of the hero, this tells FastAPI to extract the `team` too. And in the case of the team, to extract the list of `heroes` too.

//// tab | Python 3.10+

```Python hl_lines="3 8 12 17"
# Code above omitted 👆

{!./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py[ln:111-116]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py[ln:165-170]!}

# Code below omitted 👇
```

////

//// tab | Python 3.9+

```Python hl_lines="3 8 12 17"
# Code above omitted 👆

{!./docs_src/tutorial/fastapi/relationships/tutorial001_py39.py[ln:113-118]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/relationships/tutorial001_py39.py[ln:167-172]!}

# Code below omitted 👇
```

////

//// tab | Python 3.7+

```Python hl_lines="3 8 12 17"
# Code above omitted 👆
{* ./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py ln[111:116] hl[3,8,12,17] *}

{!./docs_src/tutorial/fastapi/relationships/tutorial001.py[ln:113-118]!}

# Code here omitted 👈

{!./docs_src/tutorial/fastapi/relationships/tutorial001.py[ln:167-172]!}

# Code below omitted 👇
```

////
{* ./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py ln[165:170] hl[3,8,12,17] *}

/// details | 👀 Full file preview

//// tab | Python 3.10+

```Python
{!./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py!}
```

////

//// tab | Python 3.9+

```Python
{!./docs_src/tutorial/fastapi/relationships/tutorial001_py39.py!}
```

////

//// tab | Python 3.7+

```Python
{!./docs_src/tutorial/fastapi/relationships/tutorial001.py!}
```

////

///
{* ./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py *}

## Check It Out in the Docs UI

Expand Down
Loading