diff --git a/bookmarks/templates/bookmarks/index.html b/bookmarks/templates/bookmarks/index.html index 7f3cf69..bcee6bf 100644 --- a/bookmarks/templates/bookmarks/index.html +++ b/bookmarks/templates/bookmarks/index.html @@ -22,4 +22,13 @@ {% endfor %} +
+ {% endblock %} diff --git a/bookmarks/views/bookmarks.py b/bookmarks/views/bookmarks.py index 9571d8c..adc7adb 100644 --- a/bookmarks/views/bookmarks.py +++ b/bookmarks/views/bookmarks.py @@ -1,3 +1,4 @@ +from django.core.paginator import Paginator from django.http import HttpResponseRedirect, HttpRequest from django.shortcuts import render from django.urls import reverse @@ -5,14 +6,24 @@ from django.urls import reverse from bookmarks.models import Bookmark, BookmarkForm from bookmarks.services.bookmarks import create_bookmark, update_bookmark +_default_page_size = 30 + def index(request): + page = request.GET.get('page') + paginator = Paginator(_get_bookmark_list(), _default_page_size) + bookmarks = paginator.get_page(page) + context = { - 'bookmarks': Bookmark.objects.all() + 'bookmarks': bookmarks } return render(request, 'bookmarks/index.html', context) +def _get_bookmark_list(): + return Bookmark.objects.order_by('-date_added') + + def new(request: HttpRequest): if request.method == 'POST': form = BookmarkForm(request.POST)