From 705442e54f5629fd4bc80f5278e379f051a29f55 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 20 Feb 2025 18:41:41 +0100 Subject: [PATCH] ordered from update list of devices --- dashboard/views.py | 14 ++++++++++++-- device/models.py | 10 ++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/dashboard/views.py b/dashboard/views.py index 369567b..b4d51ee 100644 --- a/dashboard/views.py +++ b/dashboard/views.py @@ -52,8 +52,18 @@ class LotDashboardView(InventaryMixin, DetailsMixin): "device_id", flat=True ).distinct() - chids_page = chids[offset:offset+limit] - return [Device(id=x) for x in chids_page], chids.count() + props = SystemProperty.objects.filter( + owner=self.request.user.institution, + value__in=chids + ).order_by("-created") + + chids_ordered = [] + for x in props: + if x.value not in chids_ordered: + chids_ordered.append(x.value) + + chids_page = chids_ordered[offset:offset+limit] + return [Device(id=x) for x in chids_page], len(chids_ordered) class SearchView(InventaryMixin): diff --git a/device/models.py b/device/models.py index 3c7c04c..4a1f506 100644 --- a/device/models.py +++ b/device/models.py @@ -143,6 +143,7 @@ class Device: SELECT t1.value, t1.key, + t1.created, ROW_NUMBER() OVER ( PARTITION BY t1.uuid ORDER BY @@ -162,6 +163,7 @@ class Device: RankedProperties WHERE row_num = 1 + ORDER BY created DESC """.format( institution=institution.id, algorithm=institution.algorithm, @@ -188,6 +190,7 @@ class Device: SELECT t1.value, t1.key, + t1.created, ROW_NUMBER() OVER ( PARTITION BY t1.uuid ORDER BY @@ -208,6 +211,7 @@ class Device: RankedProperties WHERE row_num = 1 + ORDER BY created DESC """.format( institution=institution.id, algorithm=institution.algorithm @@ -225,6 +229,7 @@ class Device: SELECT t1.value, t1.key, + t1.created, ROW_NUMBER() OVER ( PARTITION BY t1.uuid ORDER BY @@ -246,6 +251,7 @@ class Device: RankedProperties WHERE row_num = 1 + ORDER BY created DESC """.format( institution=institution.id, algorithm=institution.algorithm @@ -272,6 +278,7 @@ class Device: SELECT t1.value, t1.key, + t1.created, ROW_NUMBER() OVER ( PARTITION BY t1.uuid ORDER BY @@ -293,6 +300,7 @@ class Device: RankedProperties WHERE row_num = 1 + ORDER BY created DESC """.format( institution=institution.id, algorithm=institution.algorithm @@ -308,6 +316,7 @@ class Device: SELECT t1.value, t1.key, + t1.created, ROW_NUMBER() OVER ( PARTITION BY t1.uuid ORDER BY @@ -328,6 +337,7 @@ class Device: RankedProperties WHERE row_num = 1; + ORDER BY created DESC """.format( uuid=uuid.replace("-", ""), institution=institution.id,