Skip to content

Instantly share code, notes, and snippets.

@solidpple
Created December 18, 2017 12:00
Show Gist options
  • Save solidpple/9b6c9bcbd165596ef713ade155f8f66c to your computer and use it in GitHub Desktop.
Save solidpple/9b6c9bcbd165596ef713ade155f8f66c to your computer and use it in GitHub Desktop.
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views import generic
from .models import Choice, Question
class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'
def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.order_by('-pub_date')[:5]
class DetailView(generic.DetailView):
model = Question
template_name = 'polls/detail.html'
class ResultsView(generic.DetailView):
model = Question
template_name = 'polls/results.html'
def vote(request, question_id):
... # same as above, no changes needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment