mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-21 12:52:13 -05:00
Use an exists subquery
This commit is contained in:
parent
ef389348e5
commit
4d2e211ec1
@ -10,6 +10,7 @@ from django.db.models import Case
|
|||||||
from django.db.models import CharField
|
from django.db.models import CharField
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from django.db.models import DateTimeField
|
from django.db.models import DateTimeField
|
||||||
|
from django.db.models import Exists
|
||||||
from django.db.models import FloatField
|
from django.db.models import FloatField
|
||||||
from django.db.models import IntegerField
|
from django.db.models import IntegerField
|
||||||
from django.db.models import OuterRef
|
from django.db.models import OuterRef
|
||||||
@ -914,13 +915,11 @@ class DocumentsOrderingFilter(OrderingFilter):
|
|||||||
# We need to annotate the queryset with the custom field value
|
# We need to annotate the queryset with the custom field value
|
||||||
custom_field_value=annotation,
|
custom_field_value=annotation,
|
||||||
# We also need to annotate the queryset with a boolean for sorting whether the field exists
|
# We also need to annotate the queryset with a boolean for sorting whether the field exists
|
||||||
has_field=Case(
|
has_field=Exists(
|
||||||
When(
|
CustomFieldInstance.objects.filter(
|
||||||
custom_fields__field_id=custom_field_id,
|
document_id=OuterRef("id"),
|
||||||
then=Value(1),
|
field_id=custom_field_id,
|
||||||
),
|
),
|
||||||
default=Value(0),
|
|
||||||
output_field=IntegerField(),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user