<s> from django . shortcuts import get_object_or_404 , render <EOL> from django . http import HttpResponseRedirect <EOL> from django . core . urlresolvers import reverse <EOL> from django . views import generic <EOL> from django . utils import timezone <EOL> from . models import Choice , Question <EOL> class IndexView ( generic . ListView ) : <EOL> template_name = '<STR_LIT>' <EOL> context_object_name = '<STR_LIT>' <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> return Question . objects . filter ( <EOL> pub_date__lte = timezone . now ( ) <EOL> ) . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:5> ] <EOL> class DetailView ( generic . DetailView ) : <EOL> model = Question <EOL> template_name = '<STR_LIT>' <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> return Question . objects . filter ( pub_date__lte = timezone . now ( ) ) <EOL> class ResultsView ( generic . DetailView ) : <EOL> model = Question <EOL> template_name = '<STR_LIT>' <EOL> def vote ( request , question_id ) : <EOL> p = get_object_or_404 ( Question , pk = question_id ) <EOL> try : <EOL> selected_choice = p . choice_set . get ( pk = request . POST [ '<STR_LIT>' ] ) <EOL> except ( KeyError , Choice . DoesNotExist ) : <EOL> return render ( request , '<STR_LIT>' , { <EOL> '<STR_LIT>' : p , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> } ) <EOL> else : <EOL> selected_choice . votes += <NUM_LIT:1> <EOL> selected_choice . save ( ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , args = ( p . id , ) ) ) </s>
