Implement basic paging
This commit is contained in:
parent
9eefd479c6
commit
0177660cf6
@ -22,4 +22,13 @@
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<div class="pagination">
|
||||
{% if bookmarks.has_next %}
|
||||
<a href="?page={{ bookmarks.next_page_number }}">< Older</a>
|
||||
{% endif %}
|
||||
{% if bookmarks.has_previous %}
|
||||
<a href="?page={{ bookmarks.previous_page_number }}">Newer ></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user