mirror of
https://gitlab.aachen.ccc.de/inventory/in.git
synced 2024-11-25 16:53:59 +01:00
sort by ID only
This commit is contained in:
parent
6b7c741658
commit
07c06b6dca
1 changed files with 2 additions and 2 deletions
4
main.py
4
main.py
|
@ -30,8 +30,8 @@ def _set_sqlite_pragma(conn, _):
|
||||||
|
|
||||||
@app.get("/api/items", response_model=dict[str, Item])
|
@app.get("/api/items", response_model=dict[str, Item])
|
||||||
async def list_items(db: Session = Depends(get_db)):
|
async def list_items(db: Session = Depends(get_db)):
|
||||||
# sort by type, id (natural)
|
# natural sort by id
|
||||||
natsort = lambda item: [item.type or ''] + [int(t) if t.isdigit() else t.lower() for t in re.split('(\d+)', item.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 = crud.get_items(db)
|
||||||
items = sorted(items, key=natsort)
|
items = sorted(items, key=natsort)
|
||||||
return {i.id:i for i in items}
|
return {i.id:i for i in items}
|
||||||
|
|
Loading…
Reference in a new issue