From c3aa1edd5ae51068191f7ca5bbed54151e1a8982 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 20 Sep 2022 17:25:09 +0200 Subject: [PATCH] get the last update of one device --- ereuse_devicehub/resources/device/models.py | 8 ++++++++ ereuse_devicehub/templates/inventory/device_list.html | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index b55d9eb7..5a40cfc6 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -629,6 +629,14 @@ class Device(Thing): return self.binding.device.devicehub_id return self.devicehub_id + @property + def get_updated(self): + if self.placeholder and self.placeholder.binding: + return max([self.updated, self.placeholder.binding.updated]) + if self.binding: + return max([self.updated, self.binding.device.updated]) + return self.updated + @declared_attr def __mapper_args__(cls): """Defines inheritance. diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 6d0f1ad7..1d4e00f1 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -437,7 +437,7 @@ {% if dev.status %}{{ dev.status.type }}{% endif %} {% if dev.allocated_status %}{{ dev.allocated_status.type }}{% endif %} {% if dev.physical_status %}{{ dev.physical_status.type }}{% endif %} - {{ dev.updated.strftime('%Y-%m-%d %H:%M:%S')}} + {{ dev.get_updated.strftime('%Y-%m-%d %H:%M:%S')}} {{ dev.created.strftime('%Y-%m-%d %H:%M:%S')}}