parent
917e6b6167
commit
247fe8e206
|
@ -174,6 +174,32 @@
|
|||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<nav aria-label="Page navigation example" class="mt-5">
|
||||
<ul class="pagination justify-content-center">
|
||||
{% if page_obj.has_previous %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="?{% query_transform page=1 %}">First</a>
|
||||
</li>
|
||||
<li class="page-item">
|
||||
<a class="page-link"
|
||||
href="?{% query_transform page=page_obj.previous_page_number %}">{{ page_obj.previous_page_number }}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="">{{ page_obj.number }}</a>
|
||||
</li>
|
||||
{% if page_obj.has_next %}
|
||||
<li class="page-item">
|
||||
<a class="page-link"
|
||||
href="?{% query_transform page=page_obj.next_page_number %}">{{ page_obj.next_page_number }}</a>
|
||||
</li>
|
||||
<li class="page-item">
|
||||
<a class="page-link"
|
||||
href="?{% query_transform page=page_obj.paginator.num_pages %}">Last</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -57,6 +57,7 @@ class Browse(ListView):
|
|||
model = BlogPost
|
||||
template_name = "blog/browse.html"
|
||||
context_object_name = "posts"
|
||||
paginate_by = 20
|
||||
allow_empty = False # but we have a special get method
|
||||
|
||||
def get_queryset(self):
|
||||
|
|
|
@ -13,3 +13,13 @@ register = Library()
|
|||
@register.simple_tag
|
||||
def format_time(timestamp: datetime, format: str = "%F %H:%M:%S %Z") -> str:
|
||||
return timestamp.strftime(format)
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def query_transform(context, **kwargs):
|
||||
"""
|
||||
Modify the GET parameters of a request from templates
|
||||
"""
|
||||
query = context['request'].GET.copy()
|
||||
for k, v in kwargs.items():
|
||||
query[k] = v
|
||||
return query.urlencode()
|
||||
|
|
Loading…
Reference in New Issue