From 0cdc82a4b3b14551a35c6dbd450b77ec4259313f Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 14 Oct 2021 14:24:17 +1100 Subject: [PATCH] Annotate BuildList queryset with integer cast of the reference --- InvenTree/build/serializers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/InvenTree/build/serializers.py b/InvenTree/build/serializers.py index 547f565905..f2bf97cf7f 100644 --- a/InvenTree/build/serializers.py +++ b/InvenTree/build/serializers.py @@ -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):