fix resource agragation otion last value query

This commit is contained in:
Jorge Pastor 2023-09-25 11:47:24 +02:00 committed by Marc Aymerich
parent 44b2720b3e
commit 2cd20465c9
1 changed files with 6 additions and 1 deletions

View File

@ -32,7 +32,12 @@ class Last(Aggregation):
verbose_name = _("Last value")
def filter(self, dataset, date=None):
dataset = dataset.order_by('object_id', '-id').distinct('monitor')
# dataset = dataset.order_by('object_id', '-id').distinct('monitor')
now = timezone.now()
epoch = now - datetime.timedelta(minutes=2)
dataset = dataset.filter( created_at__range=(epoch, now ))
if date is not None:
dataset = dataset.filter(created_at__lte=date)
return dataset