- fix chart and legend to correctly show results
main
Guy Davis 9 months ago
parent b7431e26fc
commit 1802cd49c6

@ -49,8 +49,10 @@ def poll_results(
results = Vote.objects.filter( results = Vote.objects.filter(
poll=poll, poll=poll,
).values(
"option",
).annotate( ).annotate(
count=Count("option") count=Count("option"),
) )
colors = [ colors = [
@ -62,19 +64,19 @@ def poll_results(
] ]
legend = [] legend = []
index = 0 index = 0
for vote in results: for option in results:
legend.append( legend.append(
{ {
"color": colors[index % len(colors)], "color": colors[index % len(colors)],
"option": vote.option.text, "option": Option.objects.get(pk=option["option"]).text,
"count": vote.count, "count": option["count"],
} }
) )
index += 1 index += 1
chart_data = { chart_data = {
vote.option.text: vote.count Option.objects.get(pk=option["option"]).text: option["count"]
for vote in results for option in results
} }
context["chart"] = PieChart( context["chart"] = PieChart(

Loading…
Cancel
Save

Powered by TurnKey Linux.