4.6 KiB
💪 - ℹ
ℹ ❎ ⏮️ PUT
ℹ 🏬 👆 💪 ⚙️ 🇺🇸🔍 PUT
🛠️.
👆 💪 ⚙️ jsonable_encoder
🗜 🔢 💽 📊 👈 💪 🏪 🎻 (✅ ⏮️ ☁ 💽). 🖼, 🏭 datetime
str
.
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="30-35"
{!> ../../../docs_src/body_updates/tutorial001.py!}
```
=== "🐍 3️⃣.9️⃣ & 🔛"
```Python hl_lines="30-35"
{!> ../../../docs_src/body_updates/tutorial001_py39.py!}
```
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
```Python hl_lines="28-33"
{!> ../../../docs_src/body_updates/tutorial001_py310.py!}
```
PUT
⚙️ 📨 💽 👈 🔜 ❎ ♻ 💽.
⚠ 🔃 ❎
👈 ⛓ 👈 🚥 👆 💚 ℹ 🏬 bar
⚙️ PUT
⏮️ 💪 ⚗:
{
"name": "Barz",
"price": 3,
"description": None,
}
↩️ ⚫️ 🚫 🔌 ⏪ 🏪 🔢 "tax": 20.2
, 🔢 🏷 🔜 ✊ 🔢 💲 "tax": 10.5
.
& 📊 🔜 🖊 ⏮️ 👈 "🆕" tax
10.5
.
🍕 ℹ ⏮️ PATCH
👆 💪 ⚙️ 🇺🇸🔍 PATCH
🛠️ 🍕 ℹ 💽.
👉 ⛓ 👈 👆 💪 📨 🕴 💽 👈 👆 💚 ℹ, 🍂 🎂 🐣.
!!! note
PATCH
🌘 🛎 ⚙️ & 💭 🌘 PUT
.
& 📚 🏉 ⚙️ 🕴 `PUT`, 🍕 ℹ.
👆 **🆓** ⚙️ 👫 👐 👆 💚, **FastAPI** 🚫 🚫 🙆 🚫.
✋️ 👉 🦮 🎦 👆, 🌖 ⚖️ 🌘, ❔ 👫 🎯 ⚙️.
⚙️ Pydantic exclude_unset
🔢
🚥 👆 💚 📨 🍕 ℹ, ⚫️ 📶 ⚠ ⚙️ 🔢 exclude_unset
Pydantic 🏷 .dict()
.
💖 item.dict(exclude_unset=True)
.
👈 🔜 🏗 dict
⏮️ 🕴 💽 👈 ⚒ 🕐❔ 🏗 item
🏷, 🚫 🔢 💲.
⤴️ 👆 💪 ⚙️ 👉 🏗 dict
⏮️ 🕴 💽 👈 ⚒ (📨 📨), 🚫 🔢 💲:
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="34"
{!> ../../../docs_src/body_updates/tutorial002.py!}
```
=== "🐍 3️⃣.9️⃣ & 🔛"
```Python hl_lines="34"
{!> ../../../docs_src/body_updates/tutorial002_py39.py!}
```
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
```Python hl_lines="32"
{!> ../../../docs_src/body_updates/tutorial002_py310.py!}
```
⚙️ Pydantic update
🔢
🔜, 👆 💪 ✍ 📁 ♻ 🏷 ⚙️ .copy()
, & 🚶♀️ update
🔢 ⏮️ dict
⚗ 💽 ℹ.
💖 stored_item_model.copy(update=update_data)
:
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="35"
{!> ../../../docs_src/body_updates/tutorial002.py!}
```
=== "🐍 3️⃣.9️⃣ & 🔛"
```Python hl_lines="35"
{!> ../../../docs_src/body_updates/tutorial002_py39.py!}
```
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
```Python hl_lines="33"
{!> ../../../docs_src/body_updates/tutorial002_py310.py!}
```
🍕 ℹ 🌃
📄, ✔ 🍕 ℹ 👆 🔜:
- (⚗) ⚙️
PATCH
↩️PUT
. - 🗃 🏪 💽.
- 🚮 👈 💽 Pydantic 🏷.
- 🏗
dict
🍵 🔢 💲 ⚪️➡️ 🔢 🏷 (⚙️exclude_unset
).- 👉 🌌 👆 💪 ℹ 🕴 💲 🤙 ⚒ 👩💻, ↩️ 🔐 💲 ⏪ 🏪 ⏮️ 🔢 💲 👆 🏷.
- ✍ 📁 🏪 🏷, 🛠️ ⚫️ 🔢 ⏮️ 📨 🍕 ℹ (⚙️
update
🔢). - 🗜 📁 🏷 🕳 👈 💪 🏪 👆 💽 (🖼, ⚙️
jsonable_encoder
).- 👉 ⭐ ⚙️ 🏷
.dict()
👩🔬 🔄, ✋️ ⚫️ ⚒ 💭 (& 🗜) 💲 💽 🆎 👈 💪 🗜 🎻, 🖼,datetime
str
.
- 👉 ⭐ ⚙️ 🏷
- 🖊 💽 👆 💽.
- 📨 ℹ 🏷.
=== "🐍 3️⃣.6️⃣ & 🔛"
```Python hl_lines="30-37"
{!> ../../../docs_src/body_updates/tutorial002.py!}
```
=== "🐍 3️⃣.9️⃣ & 🔛"
```Python hl_lines="30-37"
{!> ../../../docs_src/body_updates/tutorial002_py39.py!}
```
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
```Python hl_lines="28-35"
{!> ../../../docs_src/body_updates/tutorial002_py310.py!}
```
!!! tip
👆 💪 🤙 ⚙️ 👉 🎏 ⚒ ⏮️ 🇺🇸🔍 PUT
🛠️.
✋️ 🖼 📥 ⚙️ `PATCH` ↩️ ⚫️ ✍ 👫 ⚙️ 💼.
!!! note 👀 👈 🔢 🏷 ✔.
, 🚥 👆 💚 📨 🍕 ℹ 👈 💪 🚫 🌐 🔢, 👆 💪 ✔️ 🏷 ⏮️ 🌐 🔢 ™ 📦 (⏮️ 🔢 💲 ⚖️ `None`).
🔬 ⚪️➡️ 🏷 ⏮️ 🌐 📦 💲 **ℹ** & 🏷 ⏮️ ✔ 💲 **🏗**, 👆 💪 ⚙️ 💭 🔬 [➕ 🏷](extra-models.md){.internal-link target=_blank}.