Sqlalchemy Update Row: Part #51 Python API Course

preview_player
Показать описание
Enjoy this completely free 19 hour course on developing an API in python using FastAPI. We will build a an api for a social media type app as well as learn to setup automatic tests and deploy the app and finally we'll also learn how to setup a CI/CD workflow using github actions.

Full Course Playlist:

Github Repo:

If you like this video please subscribe to this channel. Don't let me go hungry! 🎁

▬▬▬▬▬▬ Support this garbage Channel 🍒 ▬▬▬▬▬▬

▬▬▬▬▬▬ Stalk me on Social Media 😲 ▬▬▬▬▬▬
Рекомендации по теме
Комментарии
Автор

3:31 You are giving post.dict() = post_query.first() which throws attribute error.

dineshghatani
Автор

Why did you use post_query instead of post when you did the update?

lucasdorazio
Автор

@app.put("/posts/{id}")

def update_post(id: int, post: Post, db: Session = Depends(get_db)):

postToUpdate = == id).first()

if postToUpdate is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,
detail=f"post with ID - {id}: not updated")

post_data = # Use exclude_unset to avoid updating fields that were not provided

for key, value in post_data.items():
setattr(postToUpdate, key, value)

db.commit()

db.refresh(postToUpdate)

return {"data": postToUpdate}

arunkumaralagarsamy
join shbcf.ru