fix: the error in obtaining the document list (#2406)

This commit is contained in:
shaohuzhang1 2025-02-26 10:26:42 +08:00 committed by GitHub
parent 62ae8d124b
commit c6c3799d08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 5 deletions

View File

@ -19,7 +19,7 @@ from typing import List, Dict
import openpyxl
from celery_once import AlreadyQueued
from django.core import validators
from django.db import transaction
from django.db import transaction, models
from django.db.models import QuerySet, Count
from django.db.models.functions import Substr, Reverse
from django.http import HttpResponse
@ -28,7 +28,7 @@ from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE
from rest_framework import serializers
from xlwt import Utils
from common.db.search import native_search, native_page_search
from common.db.search import native_search, native_page_search, get_dynamics_model
from common.event import ListenerManagement
from common.event.common import work_thread_pool
from common.exception.app_exception import AppApiException
@ -443,11 +443,17 @@ class DocumentSerializers(ApiMixin, serializers.Serializer):
else:
query_set = query_set.filter(status__iregex='^[2n]*$')
order_by = self.data.get('order_by', '')
order_by_query_set = QuerySet(model=get_dynamics_model(
{'char_length': models.CharField(), 'paragraph_count': models.IntegerField(),
"update_time": models.IntegerField(), 'create_time': models.DateTimeField()}))
if order_by:
query_set = query_set.order_by(order_by)
order_by_query_set = order_by_query_set.order_by(order_by)
else:
query_set = query_set.order_by('-create_time', 'id')
return query_set
order_by_query_set = order_by_query_set.order_by('-create_time', 'id')
return {
'document_custom_sql': query_set,
'order_by_query': order_by_query_set
}
def list(self, with_valid=False):
if with_valid:

View File

@ -1,3 +1,4 @@
SELECT * from (
SELECT
"document".* ,
to_json("document"."meta") as meta,
@ -5,3 +6,6 @@ SELECT
(SELECT "count"("id") FROM "paragraph" WHERE document_id="document"."id") as "paragraph_count"
FROM
"document" "document"
${document_custom_sql}
) temp
${order_by_query}