this is view
def results(request, poll_id):
p = get_object_or_404(Poll, pk=poll_id)
choices = p.choice_set.all()
total_poll_votes = sum(c.votes for c in choices)
percentage = {}
for choice in choices:
vote = choice.votes
vote_percentage = int((choice.votes)/(total_poll_votes)) * 100
# then create a mapping here
percentage[choice.id] = vote_percentage
return render_to_response('polls/results.html', {'poll': p,'total':total_poll_votes , 'percentage':percentage},
context_instance=RequestContext(request))
--------
and this result.html template
<ul>
{% for choice in poll.choice_set.all %}
<li{{ choice.votes }} -- {{percentage}}</li>
{% endfor %}
</ul>
<br>
total {{total}}
but the problem with result its will be like this
- 601 -- {1: 0, 2: 0}
- 71 -- {1: 0, 2: 0}
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment