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 for docs/tutorial/fastapi/update-extra-data.md #1187

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
312 changes: 10 additions & 302 deletions docs/tutorial/fastapi/update-extra-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,67 +38,11 @@ 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 👇
```

////
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[5:28] hl[11,15,26] *}

/// 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 *}

///

Expand All @@ -112,79 +56,11 @@ 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 👇
```

////
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[42:44] hl[11] *}

/// 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 *}

///

Expand Down Expand Up @@ -242,67 +118,11 @@ 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 👇
```

////
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[55:64] hl[8] *}

/// 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 *}

///

Expand All @@ -318,67 +138,11 @@ 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 👇
```

////
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[83:89] hl[9] *}

/// 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 *}

///

Expand All @@ -390,67 +154,11 @@ 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 👇
```

////
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[83:99] hl[15] *}

/// 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 *}

///

Expand Down
Loading