From 868aabc666de5103d8b83b41ed8259c5169ab27f 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 8d38bf1..a248855 100644 --- a/device/models.py +++ b/device/models.py @@ -144,6 +144,7 @@ class Device: SELECT t1.value, t1.key, + t1.created, ROW_NUMBER() OVER ( PARTITION BY t1.uuid ORDER BY @@ -163,6 +164,7 @@ class Device: RankedProperties WHERE row_num = 1 + ORDER BY created DESC """.format( institution=institution.id, algorithm=institution.algorithm, @@ -189,6 +191,7 @@ class Device: SELECT t1.value, t1.key, + t1.created, ROW_NUMBER() OVER ( PARTITION BY t1.uuid ORDER BY @@ -209,6 +212,7 @@ class Device: RankedProperties WHERE row_num = 1 + ORDER BY created DESC """.format( institution=institution.id, algorithm=institution.algorithm @@ -226,6 +230,7 @@ class Device: SELECT t1.value, t1.key, + t1.created, ROW_NUMBER() OVER ( PARTITION BY t1.uuid ORDER BY @@ -247,6 +252,7 @@ class Device: RankedProperties WHERE row_num = 1 + ORDER BY created DESC """.format( institution=institution.id, algorithm=institution.algorithm @@ -273,6 +279,7 @@ class Device: SELECT t1.value, t1.key, + t1.created, ROW_NUMBER() OVER ( PARTITION BY t1.uuid ORDER BY @@ -294,6 +301,7 @@ class Device: RankedProperties WHERE row_num = 1 + ORDER BY created DESC """.format( institution=institution.id, algorithm=institution.algorithm @@ -309,6 +317,7 @@ class Device: SELECT t1.value, t1.key, + t1.created, ROW_NUMBER() OVER ( PARTITION BY t1.uuid ORDER BY @@ -329,6 +338,7 @@ class Device: RankedProperties WHERE row_num = 1; + ORDER BY created DESC """.format( uuid=uuid.replace("-", ""), institution=institution.id,