From a9fb1fb01e322ad949c5846b74c6d2a017918a15 Mon Sep 17 00:00:00 2001 From: Yipeng1217 <1329941901@qq.com> Date: Thu, 11 Jun 2026 16:49:06 +0800 Subject: [PATCH] fix todo app: auto-increment id on create Co-authored-by: Cursor --- src/open_apps/apps/todo_app/main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/open_apps/apps/todo_app/main.py b/src/open_apps/apps/todo_app/main.py index 3e9567d..92a2252 100644 --- a/src/open_apps/apps/todo_app/main.py +++ b/src/open_apps/apps/todo_app/main.py @@ -173,8 +173,13 @@ def delete(id: int): @rt("/todo") -def post(todo: Todo): - return todos.insert(todo), mk_input(hx_swap_oob="true") +def post(title: str): + # 计算新待办ID:取现有最大id,无数据则从0开始自增 + new_id = max([t.id for t in todos()], default=-1) + 1 + # 插入新Todo对象,done默认未完成 + todos.upsert(Todo(id=new_id, title=title, done=False)) + # 返回最新插入的一条数据 + 前端刷新标记 + return todos[-1], mk_input(hx_swap_oob="true") @rt("/todo/edit/{id}")