From 560324489452ea38b198e6e015322768037f0a83 Mon Sep 17 00:00:00 2001 From: Remy van der Wereld Date: Tue, 31 Dec 2024 11:56:52 +0100 Subject: [PATCH] Sort detailed registrations by creation date in descending order --- app/apps/addresses/views.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/apps/addresses/views.py b/app/apps/addresses/views.py index 233ca955a..7828b2bf6 100644 --- a/app/apps/addresses/views.py +++ b/app/apps/addresses/views.py @@ -292,6 +292,13 @@ def registrations(self, request, bag_id): except Exception as e: print(f"Error fetching details for {registration_number}: {e}") + # Sort detailed_registrations by 'createdAt' with the newest first + detailed_registrations = sorted( + detailed_registrations, + key=lambda x: x.get("createdAt", ""), + reverse=True, + ) + serializer = RegistrationDetailsSerializer( detailed_registrations, many=True )