fix: the error in obtaining the document list (#2406)
This commit is contained in:
parent
62ae8d124b
commit
c6c3799d08
@ -19,7 +19,7 @@ from typing import List, Dict
|
|||||||
import openpyxl
|
import openpyxl
|
||||||
from celery_once import AlreadyQueued
|
from celery_once import AlreadyQueued
|
||||||
from django.core import validators
|
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 import QuerySet, Count
|
||||||
from django.db.models.functions import Substr, Reverse
|
from django.db.models.functions import Substr, Reverse
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
@ -28,7 +28,7 @@ from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from xlwt import Utils
|
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 import ListenerManagement
|
||||||
from common.event.common import work_thread_pool
|
from common.event.common import work_thread_pool
|
||||||
from common.exception.app_exception import AppApiException
|
from common.exception.app_exception import AppApiException
|
||||||
@ -443,11 +443,17 @@ class DocumentSerializers(ApiMixin, serializers.Serializer):
|
|||||||
else:
|
else:
|
||||||
query_set = query_set.filter(status__iregex='^[2n]*$')
|
query_set = query_set.filter(status__iregex='^[2n]*$')
|
||||||
order_by = self.data.get('order_by', '')
|
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:
|
if order_by:
|
||||||
query_set = query_set.order_by(order_by)
|
order_by_query_set = order_by_query_set.order_by(order_by)
|
||||||
else:
|
else:
|
||||||
query_set = query_set.order_by('-create_time', 'id')
|
order_by_query_set = order_by_query_set.order_by('-create_time', 'id')
|
||||||
return query_set
|
return {
|
||||||
|
'document_custom_sql': query_set,
|
||||||
|
'order_by_query': order_by_query_set
|
||||||
|
}
|
||||||
|
|
||||||
def list(self, with_valid=False):
|
def list(self, with_valid=False):
|
||||||
if with_valid:
|
if with_valid:
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
SELECT * from (
|
||||||
SELECT
|
SELECT
|
||||||
"document".* ,
|
"document".* ,
|
||||||
to_json("document"."meta") as meta,
|
to_json("document"."meta") as meta,
|
||||||
@ -5,3 +6,6 @@ SELECT
|
|||||||
(SELECT "count"("id") FROM "paragraph" WHERE document_id="document"."id") as "paragraph_count"
|
(SELECT "count"("id") FROM "paragraph" WHERE document_id="document"."id") as "paragraph_count"
|
||||||
FROM
|
FROM
|
||||||
"document" "document"
|
"document" "document"
|
||||||
|
${document_custom_sql}
|
||||||
|
) temp
|
||||||
|
${order_by_query}
|
||||||
Loading…
Reference in New Issue
Block a user