fix resource agragation otion last value query

This commit is contained in:
Jorge Pastor 2023-09-25 11:47:24 +02:00
parent 7698f9942e
commit 69c8a3d918

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