class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_poll_list'
def get_queryset(self):
"""
Return the last five published polls (not including those set to be
published in the future).
"""
return Poll.objects.filter(
pub_date__lte=timezone.now()
).order_by('-pub_date')[:5]
add_poll = ComposePoll(request.POST or None)
if add_poll.is_valid():
create_poll = Poll.save(commit=False)
create_poll.sent = datetime.datetime.now()
create_poll.save()
return HttpResponseRedirect('/polls/')
poll = Poll.objects.filter()
return render_to_response('polls/index.html', locals(), context_instance=RequestContext(request))