[Django]-Django – get max values over several periods

5👍

You can make use of annotate() and extra():

start_date = date.today() - timedelta(days=7)

MyModel.objects.filter(timestamp__gte=start_date).extra(select={'day': connection.ops.date_trunc_sql('day', 'timestamp')}).values('day').annotate(max_temperature=Max('temperature'))
👤alecxe

Leave a comment