add tests

This commit is contained in:
Basyrov Rustam
2025-06-04 19:05:13 +03:00
parent ebf90a591b
commit 4befc5403e
3 changed files with 135 additions and 4 deletions

View File

@@ -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):