blog-browse #40
|
@ -174,6 +174,32 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</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 %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -57,6 +57,7 @@ class Browse(ListView):
|
||||||
model = BlogPost
|
model = BlogPost
|
||||||
template_name = "blog/browse.html"
|
template_name = "blog/browse.html"
|
||||||
context_object_name = "posts"
|
context_object_name = "posts"
|
||||||
|
paginate_by = 20
|
||||||
allow_empty = False # but we have a special get method
|
allow_empty = False # but we have a special get method
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
|
|
@ -13,3 +13,13 @@ register = Library()
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def format_time(timestamp: datetime, format: str = "%F %H:%M:%S %Z") -> str:
|
def format_time(timestamp: datetime, format: str = "%F %H:%M:%S %Z") -> str:
|
||||||
return timestamp.strftime(format)
|
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