Replies: 1 comment 1 reply
-
|
You can just pass a dict into update_self, e.g. this is my generic update item by id function: async def update_one(cls, id: int, dto: UpdateDTOClassType) -> ReadDTOClassType:
item = await cls.objects().where(cls.id == id).first().run()
if item is None:
raise NotFoundException.from_id(id, cls)
await item.update_self(dto.dict_without_nones()).run()
return cls.ReadDTOClass(**item.to_dict()) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
If I have a piccolo object, I want to update only some fields that are in an incoming pydantic model. So if this is my table:
I have two pydantic models to create and update a piece respectively:
Creating a new row is relatively easy, as in eg
but now I'm getting a
PieceUpdateto apply, and the only way to update all fields that need to be updated is something likeSo this looks kind of cumbersome if there are many updatable fields, and also prone to errors if at some point fields are added or removed. Am I missing a simpler method here?
When using dictionary, the update is straightforward:
Beta Was this translation helpful? Give feedback.
All reactions