Annotate BuildList queryset with integer cast of the reference

This commit is contained in:
Oliver 2021-10-14 14:24:17 +11:00
parent aa7eb3a6d0
commit 0cdc82a4b3

View File

@ -10,7 +10,8 @@ from django.core.exceptions import ValidationError as DjangoValidationError
from django.utils.translation import ugettext_lazy as _
from django.db.models import Case, When, Value
from django.db.models import BooleanField
from django.db.models import BooleanField, IntegerField
from django.db.models.functions import Cast
from rest_framework import serializers
from rest_framework.serializers import ValidationError
@ -71,6 +72,11 @@ class BuildSerializer(InvenTreeModelSerializer):
)
)
# Annotate with a "integer" version of the reference field, to be used for natural sorting
queryset = queryset.annotate(
integer_ref=Cast('reference', output_field=IntegerField())
)
return queryset
def __init__(self, *args, **kwargs):