I have this table:
id supply event_date value_average
----------------------------------------
1 a 01-01-2018 5
2 b 02-01-2018 6
3 a 02-01-2018 7
4 b 03-01-2018 8
5 c 03-01-2018 9
I am trying to get the latest value for each supply based on event_date column. I can get the latest event, but I did not found a way to return the value_average as well.
values_average = Purchase.objects \
.values('supply') \
.annotate(last=Max('event_date')) \
.order_by()
current return:
a 02-01-2018
b 03-01-2018
c 03-01-2018
expected return:
a 02-01-2018 7
b 03-01-2018 8
c 03-01-2018 9