How to filter django queryset for a current week using Django and Chart.js? In my program below, the result obtained only displays the information concerning the current day's event of the current week and does not display the information of the events of the days of the current week preceding this day.
def area_chart_week(request):
labels = []
data1 = []
data2 = []
data3 = []
today = datetime.datetime.now()
current_year=today.year
current_month=today.month
current_week = date.today().isocalendar()[1]
queryset = Even.objects.filter(date__week=current_week).filter(date__year=current_year).filter(date__month=current_month).values('date').annotate(date_positif=Sum('positif')).annotate(date_negatif=Sum('negatif')).annotate(date_null=Sum('null')).order_by('-date')
for rm in queryset:
labels.append(rm['date'])
data1.append(rm['date_positif'])
data2.append(rm['date_negatif'])
data3.append(rm['date_null'])
return JsonResponse(data={
'labels': labels,
'data1': data1,
'data2': data2,
'data3': data3,
})