Skip to content

Commit 5f8ae74

Browse files
authored
Fix list query in the dict plugin (#582)
1 parent da8e7c1 commit 5f8ae74

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

backend/plugin/dict/crud/crud_dict_type.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
3-
from sqlalchemy import Select
3+
from sqlalchemy import Select, and_, desc, select
44
from sqlalchemy.ext.asyncio import AsyncSession
5+
from sqlalchemy.orm import noload
56
from sqlalchemy_crud_plus import CRUDPlus
67

78
from backend.plugin.dict.model import DictType
@@ -30,14 +31,20 @@ async def get_list(self, *, name: str | None, code: str | None, status: int | No
3031
:param status: 字典状态
3132
:return:
3233
"""
33-
filters = {}
34+
stmt = select(self.model).options(noload(self.model.datas)).order_by(desc(self.model.created_time))
35+
36+
filters = []
3437
if name is not None:
35-
filters.update(name__like=f'%{name}%')
38+
filters.append(self.model.name.like(f'%{name}%'))
3639
if code is not None:
37-
filters.update(code__like=f'%{code}%')
40+
filters.append(self.model.code.like(f'%{code}%'))
3841
if status is not None:
39-
filters.update(status=status)
40-
return await self.select_order('created_time', 'desc', **filters)
42+
filters.append(self.model.status == status)
43+
44+
if filters:
45+
stmt = stmt.where(and_(*filters))
46+
47+
return stmt
4148

4249
async def get_by_code(self, db: AsyncSession, code: str) -> DictType | None:
4350
"""

0 commit comments

Comments
 (0)