📝 Update ModelRead to ModelPublic documentation and examples (#885)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
Esteban Maya
2024-04-08 18:07:48 -05:00
committed by GitHub
parent fa79856a4b
commit 1eb40b1f33
68 changed files with 427 additions and 427 deletions

View File

@ -17,7 +17,7 @@ class HeroCreate(SQLModel):
age: Optional[int] = None
class HeroRead(SQLModel):
class HeroPublic(SQLModel):
id: int
name: str
secret_name: str
@ -43,7 +43,7 @@ def on_startup():
create_db_and_tables()
@app.post("/heroes/", response_model=HeroRead)
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate):
with Session(engine) as session:
db_hero = Hero.model_validate(hero)
@ -53,7 +53,7 @@ def create_hero(hero: HeroCreate):
return db_hero
@app.get("/heroes/", response_model=List[HeroRead])
@app.get("/heroes/", response_model=List[HeroPublic])
def read_heroes():
with Session(engine) as session:
heroes = session.exec(select(Hero)).all()