From 82b2af8d6b612f35bbbab7cc38b17fd52ee8dddc Mon Sep 17 00:00:00 2001 From: Pratyush Desai Date: Fri, 9 Sep 2022 08:41:57 +0530 Subject: [PATCH] detail view struggle --- LCAdmin/db.sqlite3 | Bin 143360 -> 143360 bytes LCAdmin/polls/templates/polls/details.html | 6 ++++++ LCAdmin/polls/templates/polls/index.html | 9 +++++++++ LCAdmin/polls/urls.py | 7 +------ LCAdmin/polls/views.py | 12 ++++++++---- 5 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 LCAdmin/polls/templates/polls/details.html create mode 100644 LCAdmin/polls/templates/polls/index.html diff --git a/LCAdmin/db.sqlite3 b/LCAdmin/db.sqlite3 index 19e8834bfe04491d52e23fbb56ea432dae068ae3..b72e62fcbe0ba1956c3aecf8170267c81be8a613 100644 GIT binary patch delta 499 zcmZp8z|ru4V}dlJ&O{k!MxBib%i`HKGw>(#ZQj_poR6nbmx-65(bkbuoL75te!k@7 zPkGK#Mg~Skx(1d&q+nodWngJ#YNBUpVq|7+wAnQOyaF2|-yH_NI~yA>@zpmeGP3$M z2RfD*mYEhCXIB-aCKc(WdR2sF`4;<^XF7&DrRlnr z1iL%BL^!3CmL(@S2c$ZMIU4!}7Zq2=7nPJ4yz&CWU*MMg+zio13}hMiiwbhMPG1 zIz{?>B|2qiSQI!}x_dgC`uqAiRTf94yL;wmz_!2v1TeD%fB_J-1p@mo)H53a diff --git a/LCAdmin/polls/templates/polls/details.html b/LCAdmin/polls/templates/polls/details.html new file mode 100644 index 0000000..4e1bd67 --- /dev/null +++ b/LCAdmin/polls/templates/polls/details.html @@ -0,0 +1,6 @@ +

{{ question.question_text }}

+
    +{% for choice in question.choice_set.all %} +
  • {{ choice.choice_text }}
  • +{% endfor %} +
\ No newline at end of file diff --git a/LCAdmin/polls/templates/polls/index.html b/LCAdmin/polls/templates/polls/index.html new file mode 100644 index 0000000..9e8a98a --- /dev/null +++ b/LCAdmin/polls/templates/polls/index.html @@ -0,0 +1,9 @@ +{% if latest_question_list %} + +{% else %} +

No polls are available.

+{% endif %} \ No newline at end of file diff --git a/LCAdmin/polls/urls.py b/LCAdmin/polls/urls.py index 94083df..b124599 100644 --- a/LCAdmin/polls/urls.py +++ b/LCAdmin/polls/urls.py @@ -1,15 +1,10 @@ from django.urls import path from . import views - +app_name = 'polls' urlpatterns = [ path('', views.index, name='index'), - # ex: /polls/ - path('', views.index, name='index'), - # ex: /polls/5/ path('/', views.detail, name='detail'), - # ex: /polls/5/results/ path('/results/', views.results, name='results'), - # ex: /polls/5/vote/ path('/vote/', views.vote, name='vote'), ] \ No newline at end of file diff --git a/LCAdmin/polls/views.py b/LCAdmin/polls/views.py index d5f37f2..ca0fea2 100644 --- a/LCAdmin/polls/views.py +++ b/LCAdmin/polls/views.py @@ -1,14 +1,18 @@ from django.shortcuts import render - -# Create your views here. from django.http import HttpResponse +from django.shortcuts import get_object_or_404, render + +from .models import Question def index(request): - return HttpResponse("Hello, world. You're at the polls index.") + latest_question_list = Question.objects.order_by('-pub_date')[:5] + context = {'latest_question_list': latest_question_list} + return render(request, 'polls/index.html', context) def detail(request, question_id): - return HttpResponse("You're looking at question %s." % question_id) + question = get_object_or_404(Question, pk=question_id) + return render(request, 'polls/detail.html', {'question': question}) def results(request, question_id): response = "You're looking at the results of question %s."