]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/commitdiff
šŸ“ Update FastAPI tutorial docs to use the new `model.sqlmodel_update()` instead of...
authorJoel PƩrez Izquierdo <joelperez91@gmail.com>
Sun, 27 Apr 2025 13:02:41 +0000 (14:02 +0100)
committerGitHub <noreply@github.com>
Sun, 27 Apr 2025 13:02:41 +0000 (15:02 +0200)
Co-authored-by: SebastiƔn Ramƭrez <tiangolo@gmail.com>
17 files changed:
docs/contributing.md
docs/tutorial/fastapi/teams.md
docs_src/tutorial/fastapi/app_testing/tutorial001/main.py
docs_src/tutorial/fastapi/app_testing/tutorial001_py310/main.py
docs_src/tutorial/fastapi/app_testing/tutorial001_py39/main.py
docs_src/tutorial/fastapi/delete/tutorial001.py
docs_src/tutorial/fastapi/delete/tutorial001_py310.py
docs_src/tutorial/fastapi/delete/tutorial001_py39.py
docs_src/tutorial/fastapi/relationships/tutorial001.py
docs_src/tutorial/fastapi/relationships/tutorial001_py310.py
docs_src/tutorial/fastapi/relationships/tutorial001_py39.py
docs_src/tutorial/fastapi/session_with_dependency/tutorial001.py
docs_src/tutorial/fastapi/session_with_dependency/tutorial001_py310.py
docs_src/tutorial/fastapi/session_with_dependency/tutorial001_py39.py
docs_src/tutorial/fastapi/teams/tutorial001.py
docs_src/tutorial/fastapi/teams/tutorial001_py310.py
docs_src/tutorial/fastapi/teams/tutorial001_py39.py

index e3693c5a8d97f801664f1aac5daa2a10eafbe66c..8228bc4132e899b9d06999b84f143d3147e81526 100644 (file)
@@ -63,7 +63,7 @@ There is a script that you can run locally to test all the code and generate cov
 <div class="termy">
 
 ```console
-$ bash scripts/test-cov-html.sh
+$ bash scripts/test.sh
 ```
 
 </div>
index 93d38829f74ae4ec4f7cbfab86f477d3f48dd74a..4f07fb1981c12bf95cf3cf01621953e62f972e3c 100644 (file)
@@ -46,7 +46,7 @@ Let's now add the **path operations** for teams.
 
 These are equivalent and very similar to the **path operations** for the **heroes** we had before, so we don't have to go over the details for each one, let's check the code.
 
-{* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py ln[136:190] hl[136:142,145:153,156:161,164:180,183:190] *}
+{* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py ln[135:188] hl[135:141,144:152,155:160,163:178,181:188] *}
 
 ## Using Relationships Attributes
 
index f46d8b078ea7a50bb41dbb7b5c59eb927768e0e7..f0a2559467b03d32916180bf100759f50333b74b 100644 (file)
@@ -88,8 +88,7 @@ def update_hero(
     if not db_hero:
         raise HTTPException(status_code=404, detail="Hero not found")
     hero_data = hero.model_dump(exclude_unset=True)
-    for key, value in hero_data.items():
-        setattr(db_hero, key, value)
+    db_hero.sqlmodel_update(hero_data)
     session.add(db_hero)
     session.commit()
     session.refresh(db_hero)
index 702eba722b7808eedfdce1e8d13396198edaed8c..84da9fd610f7df67aa6f8f762a19e0f51f334c83 100644 (file)
@@ -86,8 +86,7 @@ def update_hero(
     if not db_hero:
         raise HTTPException(status_code=404, detail="Hero not found")
     hero_data = hero.model_dump(exclude_unset=True)
-    for key, value in hero_data.items():
-        setattr(db_hero, key, value)
+    db_hero.sqlmodel_update(hero_data)
     session.add(db_hero)
     session.commit()
     session.refresh(db_hero)
index efdfd8ee6c787cffe05aa542e6e84ecd2449b64b..e7371d84e30f987edfa58a3deb94ba7542cb411b 100644 (file)
@@ -88,8 +88,7 @@ def update_hero(
     if not db_hero:
         raise HTTPException(status_code=404, detail="Hero not found")
     hero_data = hero.model_dump(exclude_unset=True)
-    for key, value in hero_data.items():
-        setattr(db_hero, key, value)
+    db_hero.sqlmodel_update(hero_data)
     session.add(db_hero)
     session.commit()
     session.refresh(db_hero)
index 1871ab1707f9284135c96fcf42c235b5ff1432e3..977882c4c290bac3b86e271de570bf907a6a4609 100644 (file)
@@ -80,8 +80,7 @@ def update_hero(hero_id: int, hero: HeroUpdate):
         if not db_hero:
             raise HTTPException(status_code=404, detail="Hero not found")
         hero_data = hero.model_dump(exclude_unset=True)
-        for key, value in hero_data.items():
-            setattr(db_hero, key, value)
+        db_hero.sqlmodel_update(hero_data)
         session.add(db_hero)
         session.commit()
         session.refresh(db_hero)
index 0dd0c889fa90270f6311e3b99a416dfba6b2da04..f7de4019d253a26273ddc26b1bb43401ccc0b60a 100644 (file)
@@ -78,8 +78,7 @@ def update_hero(hero_id: int, hero: HeroUpdate):
         if not db_hero:
             raise HTTPException(status_code=404, detail="Hero not found")
         hero_data = hero.model_dump(exclude_unset=True)
-        for key, value in hero_data.items():
-            setattr(db_hero, key, value)
+        db_hero.sqlmodel_update(hero_data)
         session.add(db_hero)
         session.commit()
         session.refresh(db_hero)
index 9ab3056c823c0692ba34fa94a430a685b1f4f709..5d5f099abb9a14f111ae630c03afdbb4261b0c55 100644 (file)
@@ -80,8 +80,7 @@ def update_hero(hero_id: int, hero: HeroUpdate):
         if not db_hero:
             raise HTTPException(status_code=404, detail="Hero not found")
         hero_data = hero.model_dump(exclude_unset=True)
-        for key, value in hero_data.items():
-            setattr(db_hero, key, value)
+        db_hero.sqlmodel_update(hero_data)
         session.add(db_hero)
         session.commit()
         session.refresh(db_hero)
index ac8a557cfcbeb8e40091a823f4cc8ec144d5e312..59b44730baab87b77107ceaa64362860efb0dac9 100644 (file)
@@ -126,8 +126,7 @@ def update_hero(
     if not db_hero:
         raise HTTPException(status_code=404, detail="Hero not found")
     hero_data = hero.model_dump(exclude_unset=True)
-    for key, value in hero_data.items():
-        setattr(db_hero, key, value)
+    db_hero.sqlmodel_update(hero_data)
     session.add(db_hero)
     session.commit()
     session.refresh(db_hero)
@@ -183,8 +182,7 @@ def update_team(
     if not db_team:
         raise HTTPException(status_code=404, detail="Team not found")
     team_data = team.model_dump(exclude_unset=True)
-    for key, value in team_data.items():
-        setattr(db_team, key, value)
+    db_team.sqlmodel_update(team_data)
     session.add(db_team)
     session.commit()
     session.refresh(db_team)
index 5110b158b0d0eac19080881b6aa3379d52927483..47c2e5f0bc8f089012b0fd177d2bcc63e0625182 100644 (file)
@@ -124,8 +124,7 @@ def update_hero(
     if not db_hero:
         raise HTTPException(status_code=404, detail="Hero not found")
     hero_data = hero.model_dump(exclude_unset=True)
-    for key, value in hero_data.items():
-        setattr(db_hero, key, value)
+    db_hero.sqlmodel_update(hero_data)
     session.add(db_hero)
     session.commit()
     session.refresh(db_hero)
@@ -181,8 +180,7 @@ def update_team(
     if not db_team:
         raise HTTPException(status_code=404, detail="Team not found")
     team_data = team.model_dump(exclude_unset=True)
-    for key, value in team_data.items():
-        setattr(db_team, key, value)
+    db_team.sqlmodel_update(team_data)
     session.add(db_team)
     session.commit()
     session.refresh(db_team)
index a4e953c4d7f9bfd268e89ac3cdfa9ac6a12b973c..1cfa298b8bc6869ef6e9a7cd879c140b3da919cb 100644 (file)
@@ -126,8 +126,7 @@ def update_hero(
     if not db_hero:
         raise HTTPException(status_code=404, detail="Hero not found")
     hero_data = hero.model_dump(exclude_unset=True)
-    for key, value in hero_data.items():
-        setattr(db_hero, key, value)
+    db_hero.sqlmodel_update(hero_data)
     session.add(db_hero)
     session.commit()
     session.refresh(db_hero)
@@ -183,8 +182,7 @@ def update_team(
     if not db_team:
         raise HTTPException(status_code=404, detail="Team not found")
     team_data = team.model_dump(exclude_unset=True)
-    for key, value in team_data.items():
-        setattr(db_team, key, value)
+    db_team.sqlmodel_update(team_data)
     session.add(db_team)
     session.commit()
     session.refresh(db_team)
index f46d8b078ea7a50bb41dbb7b5c59eb927768e0e7..f0a2559467b03d32916180bf100759f50333b74b 100644 (file)
@@ -88,8 +88,7 @@ def update_hero(
     if not db_hero:
         raise HTTPException(status_code=404, detail="Hero not found")
     hero_data = hero.model_dump(exclude_unset=True)
-    for key, value in hero_data.items():
-        setattr(db_hero, key, value)
+    db_hero.sqlmodel_update(hero_data)
     session.add(db_hero)
     session.commit()
     session.refresh(db_hero)
index 702eba722b7808eedfdce1e8d13396198edaed8c..84da9fd610f7df67aa6f8f762a19e0f51f334c83 100644 (file)
@@ -86,8 +86,7 @@ def update_hero(
     if not db_hero:
         raise HTTPException(status_code=404, detail="Hero not found")
     hero_data = hero.model_dump(exclude_unset=True)
-    for key, value in hero_data.items():
-        setattr(db_hero, key, value)
+    db_hero.sqlmodel_update(hero_data)
     session.add(db_hero)
     session.commit()
     session.refresh(db_hero)
index efdfd8ee6c787cffe05aa542e6e84ecd2449b64b..e7371d84e30f987edfa58a3deb94ba7542cb411b 100644 (file)
@@ -88,8 +88,7 @@ def update_hero(
     if not db_hero:
         raise HTTPException(status_code=404, detail="Hero not found")
     hero_data = hero.model_dump(exclude_unset=True)
-    for key, value in hero_data.items():
-        setattr(db_hero, key, value)
+    db_hero.sqlmodel_update(hero_data)
     session.add(db_hero)
     session.commit()
     session.refresh(db_hero)
index 4289221ff51113c361c3e762eff899a5107c0c14..49dd83065a133420a8ec97daa9bcda45d296b0d2 100644 (file)
@@ -117,8 +117,7 @@ def update_hero(
     if not db_hero:
         raise HTTPException(status_code=404, detail="Hero not found")
     hero_data = hero.model_dump(exclude_unset=True)
-    for key, value in hero_data.items():
-        setattr(db_hero, key, value)
+    db_hero.sqlmodel_update(hero_data)
     session.add(db_hero)
     session.commit()
     session.refresh(db_hero)
@@ -174,8 +173,7 @@ def update_team(
     if not db_team:
         raise HTTPException(status_code=404, detail="Team not found")
     team_data = team.model_dump(exclude_unset=True)
-    for key, value in team_data.items():
-        setattr(db_team, key, value)
+    db_team.sqlmodel_update(team_data)
     session.add(db_team)
     session.commit()
     session.refresh(db_team)
index 630ae4f98ab626ecabb1075ba60970fe321bbc69..b78f059e123152b76a7f0ae0e1bf944613209fc9 100644 (file)
@@ -115,8 +115,7 @@ def update_hero(
     if not db_hero:
         raise HTTPException(status_code=404, detail="Hero not found")
     hero_data = hero.model_dump(exclude_unset=True)
-    for key, value in hero_data.items():
-        setattr(db_hero, key, value)
+    db_hero.sqlmodel_update(hero_data)
     session.add(db_hero)
     session.commit()
     session.refresh(db_hero)
@@ -172,8 +171,7 @@ def update_team(
     if not db_team:
         raise HTTPException(status_code=404, detail="Team not found")
     team_data = team.model_dump(exclude_unset=True)
-    for key, value in team_data.items():
-        setattr(db_team, key, value)
+    db_team.sqlmodel_update(team_data)
     session.add(db_team)
     session.commit()
     session.refresh(db_team)
index 661e43537347e3cae69d9b92d2ebc33833ee7e82..928ec70976343ea27b2deb232e95e30995d3407e 100644 (file)
@@ -117,8 +117,7 @@ def update_hero(
     if not db_hero:
         raise HTTPException(status_code=404, detail="Hero not found")
     hero_data = hero.model_dump(exclude_unset=True)
-    for key, value in hero_data.items():
-        setattr(db_hero, key, value)
+    db_hero.sqlmodel_update(hero_data)
     session.add(db_hero)
     session.commit()
     session.refresh(db_hero)
@@ -174,8 +173,7 @@ def update_team(
     if not db_team:
         raise HTTPException(status_code=404, detail="Team not found")
     team_data = team.model_dump(exclude_unset=True)
-    for key, value in team_data.items():
-        setattr(db_team, key, value)
+    db_team.sqlmodel_update(team_data)
     session.add(db_team)
     session.commit()
     session.refresh(db_team)