mirror of
https://github.com/Damillora/Altessimo
synced 2024-11-21 21:47:33 +00:00
Add pagination to branches
This commit is contained in:
parent
1b43a0bf65
commit
e4958148b1
@ -5,5 +5,18 @@
|
|||||||
<h2>Description</h2>
|
<h2>Description</h2>
|
||||||
<p>{{ branch.description }}</p>
|
<p>{{ branch.description }}</p>
|
||||||
<h2>Songs</h2>
|
<h2>Songs</h2>
|
||||||
{% include 'components/song-table.html' with songs=songs %}
|
{% include 'components/song-table.html' with songs=page_obj %}
|
||||||
|
<nav aria-label="Pages">
|
||||||
|
<ul class="pagination">
|
||||||
|
{% if page_obj.has_previous %}
|
||||||
|
<li class="page-item"><a class="page-link" href="?page=1">First</a></li>
|
||||||
|
<li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">Previous</a></li>
|
||||||
|
{% endif %}
|
||||||
|
<li class="page-item"><a class="page-link" href="?page={{ page_obj.number }}">{{ page_obj.number }} of {{ page_obj.paginator.num_pages }}</a></li>
|
||||||
|
{% if page_obj.has_next %}
|
||||||
|
<li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">Next</a></li>
|
||||||
|
<li class="page-item"><a class="page-link" href="?page={{ page_obj.paginator.num_pages }}">Last</a></li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -1,3 +1,4 @@
|
|||||||
|
from django.core.paginator import Paginator
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from .models import Branch, Category
|
from .models import Branch, Category
|
||||||
@ -20,4 +21,7 @@ def branch_index(request):
|
|||||||
def branch_show(request, acronym):
|
def branch_show(request, acronym):
|
||||||
branch = Branch.objects.filter(acronym=acronym)[0]
|
branch = Branch.objects.filter(acronym=acronym)[0]
|
||||||
songs = Song.objects.filter(branch=branch)
|
songs = Song.objects.filter(branch=branch)
|
||||||
return render(request,"branches/show.html",{'branch':branch,'songs':songs})
|
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})
|
Loading…
Reference in New Issue
Block a user