Шаблон:
{% extends "polls/wrapper.html" %} {% block content %} <h1>{{ question.question_text }}</h1> <ul> {% for choice in question.choice_set.all %} <li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li> {% endfor %} </ul> <p>Всего голосов: {{count_votes}}</p> <a href="{% url 'polls:detail' question.id %}">Vote again?</a> {% endblock %}
Представление:
def results(request, question_id): question = get_object_or_404(Question,pk=question_id) count_votes for choice in choice_set.all(): count_votes += choice.votes return render(request,'polls//results.html',{'question': question,'count_votes': str(count_votes),})