From e4958148b188129f94627fdf360996c03771c3f0 Mon Sep 17 00:00:00 2001 From: Damillora Date: Thu, 17 Dec 2020 01:02:21 +0700 Subject: [PATCH] Add pagination to branches --- categories/templates/branches/show.html | 15 ++++++++++++++- categories/views.py | 6 +++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/categories/templates/branches/show.html b/categories/templates/branches/show.html index 2bf5aed..1bac4fa 100644 --- a/categories/templates/branches/show.html +++ b/categories/templates/branches/show.html @@ -5,5 +5,18 @@

Description

{{ branch.description }}

Songs

- {% include 'components/song-table.html' with songs=songs %} + {% include 'components/song-table.html' with songs=page_obj %} + {% endblock %} \ No newline at end of file diff --git a/categories/views.py b/categories/views.py index 37a388e..f7e2085 100644 --- a/categories/views.py +++ b/categories/views.py @@ -1,3 +1,4 @@ +from django.core.paginator import Paginator from django.shortcuts import render from django.http import HttpResponse from .models import Branch, Category @@ -20,4 +21,7 @@ def branch_index(request): def branch_show(request, acronym): branch = Branch.objects.filter(acronym=acronym)[0] songs = Song.objects.filter(branch=branch) - return render(request,"branches/show.html",{'branch':branch,'songs':songs}) \ No newline at end of file + paginator = Paginator(songs, 100) + page_number = request.GET.get('page',1) + page_obj = paginator.get_page(page_number) + return render(request,"branches/show.html",{'branch':branch,'page_obj':page_obj}) \ No newline at end of file