Converted PlaceList into a ListView and added pagination.

This commit is contained in:
Marcus Scholz 2020-08-12 21:53:49 +02:00
parent c148cc5f10
commit 1a70c1437e

View File

@ -5,6 +5,7 @@
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.views.generic.edit import CreateView, UpdateView, DeleteView from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.views.generic import ListView
from django.views import View from django.views import View
from django.http import Http404 from django.http import Http404
from django.contrib import messages from django.contrib import messages
@ -48,12 +49,10 @@ class SignUpView(SuccessMessageMixin, CreateView):
template_name = 'signup.html' template_name = 'signup.html'
success_message = 'User created.' success_message = 'User created.'
class PlaceListView(IsAuthenticated, View): class PlaceListView(IsAuthenticated, ListView):
def get(self, request): paginate_by = 5
context = { model = Place
'place_list': Place.objects.all() template_name = 'place/place_list.html'
}
return render(request, 'place/place_list.html', context)
class PlaceDetailView(IsAuthenticated, View): class PlaceDetailView(IsAuthenticated, View):
def get(self, request, pk): def get(self, request, pk):