From 049b672c0071214364d35b2aac3423abd6ca3c1a Mon Sep 17 00:00:00 2001 From: reverend Date: Mon, 3 Aug 2020 19:14:37 +0200 Subject: [PATCH] Dedicated Home View --- lostplaces/lostplaces/urls.py | 1 - lostplaces/lostplaces_app/urls.py | 2 ++ lostplaces/lostplaces_app/views.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lostplaces/lostplaces/urls.py b/lostplaces/lostplaces/urls.py index d4ff686..57bdc01 100644 --- a/lostplaces/lostplaces/urls.py +++ b/lostplaces/lostplaces/urls.py @@ -24,7 +24,6 @@ from django.urls import path, include from django.views.generic.base import TemplateView urlpatterns = [ - path('', TemplateView.as_view(template_name='home.html'), name='home'), path('admin/', admin.site.urls), path('explorers/', include('django.contrib.auth.urls')), path('', include('lostplaces_app.urls')), diff --git a/lostplaces/lostplaces_app/urls.py b/lostplaces/lostplaces_app/urls.py index 241a5f4..feb6737 100644 --- a/lostplaces/lostplaces_app/urls.py +++ b/lostplaces/lostplaces_app/urls.py @@ -1,6 +1,7 @@ from django.urls import path from .views import ( hello_world, + HomeView, place_detail_view, place_list_view, SignUpView, @@ -10,6 +11,7 @@ from .views import ( urlpatterns = [ path('hello_world/', hello_world), # You know what this is :P + path('', HomeView.as_view(), name='home'), path('signup/', SignUpView.as_view(), name='signup'), path('place//', place_detail_view, name='place_detail'), path('place/create/', PlaceCreateView.as_view(), name='place_create'), diff --git a/lostplaces/lostplaces_app/views.py b/lostplaces/lostplaces_app/views.py index b2d5924..3706d3c 100644 --- a/lostplaces/lostplaces_app/views.py +++ b/lostplaces/lostplaces_app/views.py @@ -28,6 +28,16 @@ def place_detail_view(request, pk): def hello_world(request): return render(request, 'hello_world.html', {'text':'Hello World!'}) +class HomeView(View): + def get(self, request, *args, **kwargs): + place_list = Place.objects.all().order_by('submitted_when')[:10] + print(place_list) + context = { + 'place_list': place_list + } + return render(request, 'home.html', context) + + class PlaceUpdateView(UpdateView): template_name = 'update_place.html' model = Place