Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/open_apps/apps/todo_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down