We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 650863d commit 0b8ad53Copy full SHA for 0b8ad53
1 file changed
app/main.py
@@ -61,11 +61,9 @@ def delete_item(item_id: int):
61
def update_item(item_id: int, item_body: ItemUpdateSchema):
62
item_to_update = Item.get_by_id(item_id)
63
64
- item_to_update.title = item_body.title
65
- item_to_update.price = item_body.price
66
- item_to_update.category = item_body.category
67
- item_to_update.image_url = item_body.image_url
68
- item_to_update.description = item_body.description
+ for key, value in item_body.dict(exclude_unset=True).items():
+ setattr(item_to_update, key, value)
+
69
item_to_update.save()
70
71
return {"operation result": "record updated"}
0 commit comments