From 0613efa846cfdeac117ec8c162672e3a7152d2ce Mon Sep 17 00:00:00 2001 From: ewandor Date: Sun, 4 May 2025 17:30:28 +0200 Subject: [PATCH] Correcting label update on updating --- api/rpk-api/firm/core/models.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api/rpk-api/firm/core/models.py b/api/rpk-api/firm/core/models.py index 8a2321c..2889230 100644 --- a/api/rpk-api/firm/core/models.py +++ b/api/rpk-api/firm/core/models.py @@ -78,13 +78,16 @@ class CrudDocument(BaseModel): @classmethod async def update(cls, db, model, update_schema): - model_dict = update_schema.model_dump(mode="json") | {"updated_by": db.partner.id} + model_dict = update_schema.model_dump(mode="json") | {"updated_by": db.partner.id, "updated_at": datetime.now(UTC)} update_query = { "$set": {field: value for field, value in model_dict.items() if field!= "id" } } await cls._get_collection(db).update_one({"_id": model.id}, update_query) - return await cls.get(db, model.id) + new_model = await cls.get(db, model.id) + if new_model.label != model.label: + await cls._get_collection(db).update_one({"_id": model.id}, {"$set": {"label": new_model.label}}) + return new_model @classmethod async def delete(cls, db, model):