Added pagination to template
This commit is contained in:
parent
e646089dd6
commit
e991a17151
4 changed files with 58 additions and 2 deletions
|
@ -4,4 +4,4 @@ POSTGRES_DB=arrowcounter
|
||||||
POSTGRES_USER=arrowcounter
|
POSTGRES_USER=arrowcounter
|
||||||
POSTGRES_PASSWORD=password
|
POSTGRES_PASSWORD=password
|
||||||
SECURITY_KEY=malusa
|
SECURITY_KEY=malusa
|
||||||
ALLOWED_HOSTS=192.168.1.201
|
ALLOWED_HOSTS=*
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1 class="center">Counts</h1>
|
<h1 class="center">Counts</h1>
|
||||||
|
{% include 'pagination.html' %}
|
||||||
<table class="centered">
|
<table class="centered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -37,6 +38,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
{% include 'pagination.html' %}
|
||||||
<div class="fixed-action-btn">
|
<div class="fixed-action-btn">
|
||||||
<a class="btn-floating btn-large waves-effect waves-light red"
|
<a class="btn-floating btn-large waves-effect waves-light red"
|
||||||
href="{% url "count_new" %}">
|
href="{% url "count_new" %}">
|
||||||
|
|
47
counter/templates/pagination.html
Normal file
47
counter/templates/pagination.html
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<ul class="center pagination">
|
||||||
|
<li class="{% if page >= 2 %}waves-effect{% else %}disabled{% endif %}">
|
||||||
|
<a class="item"
|
||||||
|
href="{% if page >= 2 %}?page={{ page|add:'-1' }}{% else %}#{% endif %}">
|
||||||
|
<i class="material-icons">chevron_left</i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% if page >= 3 %}
|
||||||
|
<li class="waves-effect">
|
||||||
|
<a class="item" href="?page={{ page|add:'-2' }}">
|
||||||
|
{{ page|add:"-2" }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% if page >= 2 %}
|
||||||
|
<li class="waves-effect">
|
||||||
|
<a class="item" href="?page={{ page|add:'-1' }}">
|
||||||
|
{{ page|add:"-1" }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
<li class="active">
|
||||||
|
<a class="active item" href="#">
|
||||||
|
{{ page }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% if pageCount >= page|add:"1" %}
|
||||||
|
<li class="waves-effect">
|
||||||
|
<a class="item" href="?page={{ page|add:'1' }}">
|
||||||
|
{{ page|add:"1" }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
{% if pageCount >= page|add:"2" %}
|
||||||
|
<li class="waves-effect">
|
||||||
|
<a class="item" href="?page={{ page|add:'2' }}">
|
||||||
|
{{ page|add:"2" }}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
<li class="{% if pageCount >= page|add:'1' %}waves-effect{% else %}disabled{% endif %}">
|
||||||
|
<a class="item"
|
||||||
|
href="{% if pageCount >= page|add:'1' %}?page={{ page|add:'1' }}{% else %}#{% endif %}">
|
||||||
|
<i class="material-icons">chevron_right</i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
|
@ -30,8 +30,15 @@ def arrow_count_list(request):
|
||||||
finish = settings.ITEMS_PER_PAGE + start
|
finish = settings.ITEMS_PER_PAGE + start
|
||||||
counts = ArrowCount.objects.order_by('-date') \
|
counts = ArrowCount.objects.order_by('-date') \
|
||||||
.filter(user = request.user)[start:finish]
|
.filter(user = request.user)[start:finish]
|
||||||
|
|
||||||
|
pageCount = ArrowCount.objects.filter(user = request.user).count() / \
|
||||||
|
settings.ITEMS_PER_PAGE
|
||||||
template = loader.get_template('counter/list.html')
|
template = loader.get_template('counter/list.html')
|
||||||
return HttpResponse(template.render({'counts': counts}, request))
|
return HttpResponse(template.render({
|
||||||
|
'counts': counts,
|
||||||
|
'pageCount': pageCount,
|
||||||
|
'page': page
|
||||||
|
}, request))
|
||||||
|
|
||||||
class NewArrowCount(generic.CreateView):
|
class NewArrowCount(generic.CreateView):
|
||||||
form_class = ArrowCountForm
|
form_class = ArrowCountForm
|
||||||
|
|
Loading…
Reference in a new issue