From 16b38b0d24677e6f45760cd697e9da1cc5ebd1df Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Tue, 7 Jul 2020 22:14:26 +1000 Subject: [PATCH] finished tut4, onto tut 5 --- .../__pycache__/__init__.cpython-37.pyc | Bin 144 -> 148 bytes .../__pycache__/settings.cpython-37.pyc | Bin 2278 -> 2282 bytes mysite/mysite/__pycache__/urls.cpython-37.pyc | Bin 986 -> 990 bytes mysite/mysite/__pycache__/wsgi.cpython-37.pyc | Bin 546 -> 550 bytes .../polls/__pycache__/__init__.cpython-37.pyc | Bin 143 -> 147 bytes mysite/polls/__pycache__/admin.cpython-37.pyc | Bin 258 -> 262 bytes mysite/polls/__pycache__/apps.cpython-37.pyc | Bin 357 -> 361 bytes .../polls/__pycache__/models.cpython-37.pyc | Bin 1229 -> 1233 bytes mysite/polls/__pycache__/urls.cpython-37.pyc | Bin 453 -> 481 bytes mysite/polls/__pycache__/views.cpython-37.pyc | Bin 1504 -> 2335 bytes .../__pycache__/0001_initial.cpython-37.pyc | Bin 993 -> 997 bytes .../__pycache__/__init__.cpython-37.pyc | Bin 154 -> 158 bytes mysite/polls/templates/polls/index.html | 2 +- mysite/polls/urls.py | 6 +++--- mysite/polls/views.py | 19 +++++++++++++++++- 15 files changed, 22 insertions(+), 5 deletions(-) diff --git a/mysite/mysite/__pycache__/__init__.cpython-37.pyc b/mysite/mysite/__pycache__/__init__.cpython-37.pyc index caa798b6093d64281bb2f0773497dc54cadf9d3b..ecc92973aeef01a2fccf8f0b1a530a928fe2f436 100644 GIT binary patch delta 60 zcmbQhIE9hNiIL=!97H8;}78mKKq?YNYWF_XM=j)b~ OmgE;@Cgw~`)&&5@{1O!a delta 56 zcmbQjIDwJJiISyHVrs^l=Wfo`XmlhZ4r=*tYr(`AOrRVFG Ql$PWdWhUlKPUUC>02F2uYXATM delta 58 zcmaDQ_)L(;iIH&s6|FS9s9zqGhWKP9zHKP4+MFFjv3 MB{esH@>fPf0RDFqO#lD@ diff --git a/mysite/polls/__pycache__/__init__.cpython-37.pyc b/mysite/polls/__pycache__/__init__.cpython-37.pyc index 7e11076196a921d9b27715da36503caba73a1a90..c86605f89bf00285ecf724768427680d46387370 100644 GIT binary patch delta 60 zcmeBYoXp7M#LLUY00g2@Eb$Y0%vEgkGxBp&^%L_li!<~~i;MJAQp@yHvJ&&s^L0x~ OOY(~{6LTge>i_`8UJ?-i delta 56 zcmbQt*w4u0#LLUY00ft|e~6pNW3FJKpOK%Ns-KvbS)8F?T3n=`l3J#pl9ia3p0Asd Knwvi{T?YWtw-Q4D diff --git a/mysite/polls/__pycache__/admin.cpython-37.pyc b/mysite/polls/__pycache__/admin.cpython-37.pyc index c7dbf5fc4861ace87313e3796a068911a1a4f0a0..d1a487a154f5fb1a52c2b7ef9cfe7c3d3f3feb72 100644 GIT binary patch delta 60 zcmZo-YGdMY;^pOH00Pk{miUQ0D^)D@GxBp&^%L_li!<~~i;MJAQp@yHvJ&&s^L0x~ OOY(~{6LThB)dc|4h7#KV delta 56 zcmZo;YGUGX;^pOH0D`@ZU*ab6tW+@7&&bbB)lbaJEY8p`EiTeeNiEY)$x6&i&(}>! K&CQ>9Qx^cz#1h5; diff --git a/mysite/polls/__pycache__/apps.cpython-37.pyc b/mysite/polls/__pycache__/apps.cpython-37.pyc index 429cbd05f276d88fb2f570788f4535898bd98181..575eb8619183e3c05125b5822daaad4d13083a19 100644 GIT binary patch delta 37 rcmaFL^pc6kiIcvG6Aq_iZzC^Io<;*VSav~3Hp delta 33 ocmaFK^puImiIn6aVA_0I&NC;s5{u diff --git a/mysite/polls/__pycache__/models.cpython-37.pyc b/mysite/polls/__pycache__/models.cpython-37.pyc index c00f228a8f7f0bb62eb09d29301e043f23554d3f..a16d86e77dd5bc51b979692c808c3a410ad3eac4 100644 GIT binary patch delta 41 vcmX@hd6ARHiIGQ-sl}x^CB-045jW7Gx427-atabl zN>YpRidQle2?E8y#4ii|jQreG{lvV?;tc)L;v)T&)H3~)ti-(ZeBF}LlKi5~#2o$H a%HqtDRQ-bdoSb6)(#Z=L<=KQ7K@b2c98%5z delta 205 zcmaFJe3Y5jiI_8V3ae@etV~V(e#4Ya9qMU-nl9JS-yyBG%Mf@NM5b?`oau=gCOG;{P O{^YfcdTe}*AP4{&fHtuJ diff --git a/mysite/polls/__pycache__/views.cpython-37.pyc b/mysite/polls/__pycache__/views.cpython-37.pyc index ff3ed69585775e9faed50da63339d1f9237184b1..bc8f37fc9ce1d0f5d2b4557bd754424976b2ac1e 100644 GIT binary patch literal 2335 zcmbtVOOG2x5bo|7+hcpY>wRRi;icsrAF>815&|I{81uSpOKgPHAq^r4M`i4bx77BiDd_p&Rnt~ zSLEtLmTbzdT*G)yuFDOKTXIvL!+2h9-D17-Pl22DgsW>cmP)&|ePz?~_DBse==AbC zmwSPWKecvpQ<+IQHp(^V3kz;@S$tE;Ok-D%yLw&@a293_tqzqoil+N&taLVf%Bu^b zucpe_tQ@=g)q^q{sv#j+`~)Uf(9BEd6ic{diI6-Aq)0*;$PgCPWDOS7UGp;_zxPe1 zemd?>$~-syj0C#}w#Z%Q$N4pBo*6r&%jrjBfOZwlY@)Ml#2@2^C%8$9pTz}+vxB|k z=B3H>b}9!}J*`2l7w9$y*Qi`%TvTe9n%+KwiJ?*XonM*WfW}|%_YcZK^#|k39Q3C~ z_oX`Q%h6!GUtY3PTk33(_lqNwS=FylAHo8&J2`SO#Q?bVkx{mT!wk8DiQ}ykOLv!5 z_TYplO~->mrKxMBX;I2)PV+d$IfHz@(y^+T&Lmmn*`$yQwtyf5iwk*P?0)&hsT!LKcTGx~vWVw&mT4lNP5+5+wqPMVF zpQmn{I`8lrY*M+tKmzjbQs?2l2-zB%p^PMWnk4@jTpKK(=GH8;NqZ5o=?rk1NP0H3 zm$6E2J%vV+6Dkr73ACr;MNFQj;(acI8PE8AVS^cy;Y>UT;LF-FJ@qQK>J@a)XF)IY zPSjmeAunkn6k>t=^!efUxyGCj&-m8Wd_IxueefCI zI>esR9-yv2<5c*SyZ!SY5N>ILekIpbz z_UO^}OpL?`WEh1KwF-Xb_k(ZQ_+rRx&DKYaJK}Cj-{2^8oY@HehxcVDYrlBve8*-% z$VN?Be~$^4HfO=())Uff+gLVmcIOV4(IfGI-@+>fsx=WY?*dmJ`f9y!#Zu}XzwmuI z-I19bzioF=3h@~140bB@p73sP9i=s%l|mUa*jJh!*5lY0fe$K=P#GQQebZYxjlOGD zhomTnE04>(P3+9!9k& HjKaSGz@-o? delta 671 zcmZuv&2G~`5cW3y*~WHam!xfuNJW(o#6qICQdOKdArJ>p1cb;tG={ae>~7MQOE0`Y zwGYq}2adds4+x11eE@{SiP@x3R56z4Z)fJ4{p|C#ui^InIBq*A$@d>Gf4YwI%?5vD z1)Y6-6+heFzvD5VhgCF+h{FO#KRBb9t+F=S4hva?w##DHL7TAd6DLc~zPwH^2=-^B zp^s;vbSY}{)P2;u@G#rN?=Ev=UMg)qyM59&>B{=4w7^-b2_!5^WMs>OLev_L^(RNB z82{SIr=o&s=%yaf;QXh!h3@VXVC#uwt9}3P@J}==&4G&KmudEpyQ=FiD zR1WD8O5_dn3JZ&3w!G&LEGw6L$S(R#_;=fq$-X_cTP)R@E$|uWNy%gM6*7sFBO*7< zz}o}a!|;8&+(d$!aXp;siZAA5E!o0jc^y%%+w6almLn|w71E}8>z|XJ34?om+tkD$ zrI6zal$soXTs1F(n@I3!aElDg$KdXcz19`TsH=cOp@EHysVED$em{3EH1th}4uUQ0 ze3+$XNMAi`{7Nw3YPrAVQEphZX_YPfXU>AL1zB_#yJj5r?Ej$>R0)2F$UZIVQJ1>E E0fZHlMgRZ+ diff --git a/mysite/polls/migrations/__pycache__/0001_initial.cpython-37.pyc b/mysite/polls/migrations/__pycache__/0001_initial.cpython-37.pyc index d37e6f677a61461384f2dc8974a0e93bf74e8acf..50052e2dc5dc82867fdc76364d8a67bbca851815 100644 GIT binary patch delta 62 zcmaFJ{*;}^iI diff --git a/mysite/polls/migrations/__pycache__/__init__.cpython-37.pyc b/mysite/polls/migrations/__pycache__/__init__.cpython-37.pyc index 8005e44c77e81fdc09ea10b80b321b4772ead9d4..f7ec59ef2c8ec0a055a28d3d0b32ce24119b1bc5 100644 GIT binary patch delta 60 zcmbQmIFFIXiIL=!97H8;}78mKKq?YNYWF_XM=j)b~ OmgE;@Cgw~`HU|LBC=xvY delta 56 zcmbQoIE#_TiI {% for question in question_list %} -
  • {{ question.question_text }}
  • +
  • {{ question.question_text }}
  • {% endfor %} {% 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 }