From 78c9a67f07b01f9ed0a6c61bf0e8538e1600c76c Mon Sep 17 00:00:00 2001 From: keannu125 Date: Tue, 7 Mar 2023 18:26:00 +0800 Subject: [PATCH] Sort logs and history in descending order --- ivy/products/serializers.py | 2 +- ivy/products/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ivy/products/serializers.py b/ivy/products/serializers.py index 33dd5b4..c7dace1 100644 --- a/ivy/products/serializers.py +++ b/ivy/products/serializers.py @@ -7,7 +7,7 @@ class HistoricalRecordField(serializers.ListField): child = serializers.DictField() def to_representation(self, data): - return super().to_representation(data.values('quantity', 'history_date').order_by('history_date')) + return super().to_representation(data.values('quantity', 'history_date').order_by('-history_date')) class ProductSerializer(serializers.HyperlinkedModelSerializer): diff --git a/ivy/products/views.py b/ivy/products/views.py index 18034ea..af0f55f 100644 --- a/ivy/products/views.py +++ b/ivy/products/views.py @@ -14,4 +14,4 @@ class LogViewSet(viewsets.ModelViewSet): # permission_classes = [IsAuthenticated] http_method_names = ['get'] serializer_class = LogSerializer - queryset = Product.history.all().order_by('history_date') + queryset = Product.history.all().order_by('-history_date')