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'))
Source:stackexchange.com