From 1a70c1437eb63a34ddda0a9dfa6bd3446054ca4d Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Wed, 12 Aug 2020 21:53:49 +0200 Subject: [PATCH] Converted PlaceList into a ListView and added pagination. --- lostplaces/lostplaces_app/views.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lostplaces/lostplaces_app/views.py b/lostplaces/lostplaces_app/views.py index af042f6..125a969 100644 --- a/lostplaces/lostplaces_app/views.py +++ b/lostplaces/lostplaces_app/views.py @@ -5,6 +5,7 @@ from django.shortcuts import render, redirect, get_object_or_404 from django.urls import reverse_lazy from django.views.generic.edit import CreateView, UpdateView, DeleteView +from django.views.generic import ListView from django.views import View from django.http import Http404 from django.contrib import messages @@ -48,12 +49,10 @@ class SignUpView(SuccessMessageMixin, CreateView): template_name = 'signup.html' success_message = 'User created.' -class PlaceListView(IsAuthenticated, View): - def get(self, request): - context = { - 'place_list': Place.objects.all() - } - return render(request, 'place/place_list.html', context) +class PlaceListView(IsAuthenticated, ListView): + paginate_by = 5 + model = Place + template_name = 'place/place_list.html' class PlaceDetailView(IsAuthenticated, View): def get(self, request, pk):