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