fix: FluentQuery.filter 污染 base_qs 导致积分处罚列表为空
This commit is contained in:
1 parent
8ee7814a45
commit
a69c008f96
2 files changed
+15
-13
No files matched your search
+12
-9
@@ -453,31 +453,33 @@ class FluentQuery(Generic[_M]):
|
||||
# ---- 过滤 ----
|
||||
|
||||
def filter(self, *args: Any, **kwargs: Any) -> FluentQuery[_M]:
|
||||
"""过滤查询,支持 Q 对象和关键字参数,返回 self 以支持链式调用。"""
|
||||
"""过滤查询,支持 Q 对象和关键字参数;返回新 FluentQuery,不修改原查询。"""
|
||||
converted_args: List[Any] = []
|
||||
for arg in args:
|
||||
if isinstance(arg, Q) and self._joined_models:
|
||||
converted_args.append(self._remap_q(arg))
|
||||
else:
|
||||
converted_args.append(arg)
|
||||
self._qs = self._qs.filter(*converted_args, **kwargs)
|
||||
return self
|
||||
q = self._clone()
|
||||
q._qs = self._qs.filter(*converted_args, **kwargs)
|
||||
return q
|
||||
|
||||
def exclude(self, *args: Any, **kwargs: Any) -> FluentQuery[_M]:
|
||||
"""排除查询,返回 self 以支持链式调用。"""
|
||||
"""排除查询;返回新 FluentQuery,不修改原查询。"""
|
||||
converted_args: List[Any] = []
|
||||
for arg in args:
|
||||
if isinstance(arg, Q) and self._joined_models:
|
||||
converted_args.append(self._remap_q(arg))
|
||||
else:
|
||||
converted_args.append(arg)
|
||||
self._qs = self._qs.exclude(*converted_args, **kwargs)
|
||||
return self
|
||||
q = self._clone()
|
||||
q._qs = self._qs.exclude(*converted_args, **kwargs)
|
||||
return q
|
||||
|
||||
# ---- 排序 ----
|
||||
|
||||
def order_by(self, *args: Any) -> FluentQuery[_M]:
|
||||
"""排序,支持字符串和 FieldExpression,返回 self 以支持链式调用。"""
|
||||
"""排序,支持字符串和 FieldExpression;返回新 FluentQuery,不修改原查询。"""
|
||||
converted: List[str] = []
|
||||
for a in args:
|
||||
if isinstance(a, str):
|
||||
@@ -486,8 +488,9 @@ class FluentQuery(Generic[_M]):
|
||||
converted.append(str(a))
|
||||
else:
|
||||
converted.append(str(a))
|
||||
self._qs = self._qs.order_by(*converted)
|
||||
return self
|
||||
q = self._clone()
|
||||
q._qs = q._qs.order_by(*converted)
|
||||
return q
|
||||
|
||||
# ---- 获取记录 ----
|
||||
|
||||
|
||||
+3
-4
@@ -9059,7 +9059,6 @@ class KefuPunishmentListView(APIView):
|
||||
'yichuli': base_qs.filter(ApplyStatus__in=[1, 2]).count(),
|
||||
}
|
||||
|
||||
# 4. 构建查询条件
|
||||
queryset = base_qs
|
||||
|
||||
if status_list and isinstance(status_list, list):
|
||||
@@ -9072,9 +9071,9 @@ class KefuPunishmentListView(APIView):
|
||||
queryset = queryset.filter(PlayerID=dashouid)
|
||||
|
||||
# 5. 分页
|
||||
total = queryset.count()
|
||||
offset = (page - 1) * page_size
|
||||
records = queryset.order_by('-CreateTime')[offset:offset + page_size]
|
||||
page_obj = queryset.order_by('-CreateTime').paginate(page=page, per_page=page_size)
|
||||
total = page_obj.total
|
||||
records = page_obj.items
|
||||
|
||||
# 6. 构建返回列表
|
||||
list_data = []
|
||||
|
||||
Reference in new issue
Block a user