<div class="termy">
```console
-$ bash scripts/test-cov-html.sh
+$ bash scripts/test.sh
```
</div>
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
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)