0

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,
        })
LeeLenalee
  • 27,463
  • 6
  • 45
  • 69
  • What is the current week? A week that starts on monday, the last seven days? Something else? – Willem Van Onsem Jan 26 '22 at 16:08
  • A week that starts on Sunday. For example we are Wednesday January 26, 2022 from the week of Sunday January 23, 2022 to Saturday January 29, 2022, I want to have the events that happened during this week. That is to say from January 23 to 26, 2022. For tomorrow I will have the events produced between January 23 and 27... and on Saturday January 29, I will have the past events between January 23 and 29, 2022. – Saliha Alger Jan 26 '22 at 20:05

0 Answers0