Проблема вне диапазона с кортежем - PullRequest
0 голосов
/ 07 августа 2020

Я пытаюсь построить график с покупками за последние два месяца, но получаю сообщение «IndexError: индекс кортежа вне допустимого диапазона»

Ошибка возникает, когда я пытаюсь заполнить список с данными графика в этом уравнении:

this_month[day] = {'y': float(i[2]), 'x': week}

Вот мои запросы

queryset = delivered_orders.annotate(date=TruncDate('created_at')).values_list('date').annotate(total_price=Sum('total'))
queryset_before = delivered_orders_before.annotate(date=TruncDate('created_at')).values_list('date').annotate(total_price=Sum('total'))
by_state = Order.objects.filter(
    dispensary=request.user.dispensary,
    status=Order.DELIVERED,
).values('state').annotate(sum=Count('id'))
visitor_data = {}
for item in by_state:
    visitor_data[item['state'].lower()] = item['sum']

this_month = [{'x': i, 'y': 0} for i in range(30)]
last_month = [{'x': i, 'y': 0} for i in range(30)]
sales_chart_data_last_month = []
#print(queryset_before)

Как только я загружаю данные календаря, я вызываю его здесь:

for i in queryset:
    week =  "%s-%s" % (i[0], i[1])
    day = next((index for (index, d) in enumerate(this_month) if d["x"] == week), None)
    this_month[day] = {'y': float(i[2]), 'x': week}
...