From 07c06b6dcaa618c631c1b97c6dd3622e0601200f Mon Sep 17 00:00:00 2001 From: jomo Date: Thu, 11 Aug 2022 03:40:26 +0200 Subject: [PATCH] sort by ID only --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 8f149a0..ecaeea6 100644 --- a/main.py +++ b/main.py @@ -30,8 +30,8 @@ def _set_sqlite_pragma(conn, _): @app.get("/api/items", response_model=dict[str, Item]) async def list_items(db: Session = Depends(get_db)): - # sort by type, id (natural) - natsort = lambda item: [item.type or ''] + [int(t) if t.isdigit() else t.lower() for t in re.split('(\d+)', item.id)] + # natural sort by id + natsort = lambda item: [int(t) if t.isdigit() else t.lower() for t in re.split('(\d+)', item.id)] items = crud.get_items(db) items = sorted(items, key=natsort) return {i.id:i for i in items}