add tests
This commit is contained in:
@@ -4,6 +4,7 @@ from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.template import loader
|
||||
from django.urls import reverse
|
||||
from django.views import generic
|
||||
from django.utils import timezone
|
||||
|
||||
from .models import Question, Choice
|
||||
|
||||
@@ -13,11 +14,18 @@ class IndexView(generic.ListView):
|
||||
|
||||
def get_queryset(self):
|
||||
"""Return the last five published questions."""
|
||||
return Question.objects.order_by("-pub_date")[:5]
|
||||
return Question.objects.filter(pub_date__lte=timezone.now()).order_by("-pub_date")[
|
||||
:5
|
||||
]
|
||||
|
||||
class DetailView(generic.DetailView):
|
||||
model = Question
|
||||
template_name = "polls/detail.html"
|
||||
def get_queryset(self):
|
||||
"""
|
||||
Excludes any questions that aren't published yet.
|
||||
"""
|
||||
return Question.objects.filter(pub_date__lte=timezone.now())
|
||||
|
||||
|
||||
class ResultsView(generic.DetailView):
|
||||
|
||||
Reference in New Issue
Block a user