diff --git a/mysite/mysite/__pycache__/__init__.cpython-37.pyc b/mysite/mysite/__pycache__/__init__.cpython-37.pyc index caa798b..ecc9297 100644 Binary files a/mysite/mysite/__pycache__/__init__.cpython-37.pyc and b/mysite/mysite/__pycache__/__init__.cpython-37.pyc differ diff --git a/mysite/mysite/__pycache__/settings.cpython-37.pyc b/mysite/mysite/__pycache__/settings.cpython-37.pyc index fe3c765..6bba6b8 100644 Binary files a/mysite/mysite/__pycache__/settings.cpython-37.pyc and b/mysite/mysite/__pycache__/settings.cpython-37.pyc differ diff --git a/mysite/mysite/__pycache__/urls.cpython-37.pyc b/mysite/mysite/__pycache__/urls.cpython-37.pyc index e10d518..748b7be 100644 Binary files a/mysite/mysite/__pycache__/urls.cpython-37.pyc and b/mysite/mysite/__pycache__/urls.cpython-37.pyc differ diff --git a/mysite/mysite/__pycache__/wsgi.cpython-37.pyc b/mysite/mysite/__pycache__/wsgi.cpython-37.pyc index 9840dba..19857ca 100644 Binary files a/mysite/mysite/__pycache__/wsgi.cpython-37.pyc and b/mysite/mysite/__pycache__/wsgi.cpython-37.pyc differ diff --git a/mysite/polls/__pycache__/__init__.cpython-37.pyc b/mysite/polls/__pycache__/__init__.cpython-37.pyc index 7e11076..c86605f 100644 Binary files a/mysite/polls/__pycache__/__init__.cpython-37.pyc and b/mysite/polls/__pycache__/__init__.cpython-37.pyc differ diff --git a/mysite/polls/__pycache__/admin.cpython-37.pyc b/mysite/polls/__pycache__/admin.cpython-37.pyc index c7dbf5f..d1a487a 100644 Binary files a/mysite/polls/__pycache__/admin.cpython-37.pyc and b/mysite/polls/__pycache__/admin.cpython-37.pyc differ diff --git a/mysite/polls/__pycache__/apps.cpython-37.pyc b/mysite/polls/__pycache__/apps.cpython-37.pyc index 429cbd0..575eb86 100644 Binary files a/mysite/polls/__pycache__/apps.cpython-37.pyc and b/mysite/polls/__pycache__/apps.cpython-37.pyc differ diff --git a/mysite/polls/__pycache__/models.cpython-37.pyc b/mysite/polls/__pycache__/models.cpython-37.pyc index c00f228..a16d86e 100644 Binary files a/mysite/polls/__pycache__/models.cpython-37.pyc and b/mysite/polls/__pycache__/models.cpython-37.pyc differ diff --git a/mysite/polls/__pycache__/urls.cpython-37.pyc b/mysite/polls/__pycache__/urls.cpython-37.pyc index 10b912c..f003bd3 100644 Binary files a/mysite/polls/__pycache__/urls.cpython-37.pyc and b/mysite/polls/__pycache__/urls.cpython-37.pyc differ diff --git a/mysite/polls/__pycache__/views.cpython-37.pyc b/mysite/polls/__pycache__/views.cpython-37.pyc index ff3ed69..bc8f37f 100644 Binary files a/mysite/polls/__pycache__/views.cpython-37.pyc and b/mysite/polls/__pycache__/views.cpython-37.pyc differ diff --git a/mysite/polls/migrations/__pycache__/0001_initial.cpython-37.pyc b/mysite/polls/migrations/__pycache__/0001_initial.cpython-37.pyc index d37e6f6..50052e2 100644 Binary files a/mysite/polls/migrations/__pycache__/0001_initial.cpython-37.pyc and b/mysite/polls/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/mysite/polls/migrations/__pycache__/__init__.cpython-37.pyc b/mysite/polls/migrations/__pycache__/__init__.cpython-37.pyc index 8005e44..f7ec59e 100644 Binary files a/mysite/polls/migrations/__pycache__/__init__.cpython-37.pyc and b/mysite/polls/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/mysite/polls/templates/polls/index.html b/mysite/polls/templates/polls/index.html index de92577..a5a7c18 100644 --- a/mysite/polls/templates/polls/index.html +++ b/mysite/polls/templates/polls/index.html @@ -1,7 +1,7 @@ {% if question_list %} {% else %} diff --git a/mysite/polls/urls.py b/mysite/polls/urls.py index 06524e9..1aec99b 100644 --- a/mysite/polls/urls.py +++ b/mysite/polls/urls.py @@ -4,8 +4,8 @@ from . import views app_name = 'polls' urlpatterns = [ - path('', views.index, name='index'), - path('/', views.detail, name='detail'), - path('/results/', views.result, name='result'), + path('', views.IndexView.as_view(), name='index'), + path('/', views.DetailView.as_view(), name='detail'), + path('/results/', views.ResultsView.as_view(), name='result'), path('/vote/', views.vote, name='vote') ] diff --git a/mysite/polls/views.py b/mysite/polls/views.py index 9905f27..2d0fd3d 100644 --- a/mysite/polls/views.py +++ b/mysite/polls/views.py @@ -2,9 +2,26 @@ from django.shortcuts import render, get_object_or_404 from django.http import HttpResponse, Http404, HttpResponseRedirect from django.template import loader from django.urls import reverse -from .models import Question +from django.views import generic +from .models import Question, Choice # Create your views here. +class IndexView(generic.ListView): + template_name = 'polls/index.html' + context_object_name = 'question_list' + + def get_queryset(self): + # Return last 5 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/resulthtml' + def index(request): question_list = Question.objects.order_by('-pub_date')[:5] context = { 'question_list': question_list }