Hello, I'm using the django paginator 1.8 (paginator) works fine, but I would like you to show me the number of my pages in this way
I have 21 records that means I have 3 pages and the pager should show:
< < 1 2 3 > >
but it shows me < < 1 > >
I click on the following of changes to 2, I do not know if there is a way to show me 3 of 3 pages and when I click on any of the pages take me to those pages, I hope you let me understand here I leave the code waiting for your help soon, thanks
VIEWS.PY
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
class ListarTipoAlmacen(ListView):
model = Tipo_almacen
template_name = 'tipo_almacen/lista_tipo_almacen.html'
paginate_by = 10
def get_context_data(self, **kwargs):
context = super(ListarTipoAlmacen, self).get_context_data(**kwargs)
lista_tipo_almacen = Tipo_almacen.objects.all().order_by('descripcion')
paginator = Paginator(lista_tipo_almacen, self.paginate_by)
page = self.request.GET.get('page')
try:
tipo_almacen = paginator.page(page)
except PageNotAnInteger:
tipo_almacen = paginator.page(1)
except EmptyPage:
tipo_almacen = paginator.page(paginator.num_pages)
context['lista_tipo_almacen']= tipo_almacen
return context
LIST.HTML
introducir el código aquí
<div class="panel panel-primary">
<div class="panel-heading">
<h4>Lista de Tipo de almacen</h4>
</div>
<table class="table">
<th>Nombres</th>
<th>Acciones</th>
<tbody>
{% for data in lista_tipo_almacen %}
<tr>
<td>
{{data.descripcion}}
<td>
<a href="{% url 'editar_tipo_almacen' data.pk %}">Editar <span class="glyphicon glyphicon-edit"></span></a>
<a href="{% url 'eliminar-tipo-almacen' data.pk %}" data-toggle="modal_almacen" data-target="#modal_almacen" data-id="{{ data.descripcion }}">Eliminar <span class="glyphicon glyphicon-trash"></span></a>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% if is_paginated %}
<ul class="pagination">
{% if page_obj.has_previous %}
<li class="">
<span><a href="?page={{ page_obj.previous_page_number }}"> << </a></span>
</li>
{% endif %}
<li class="active">
<span> {{ page_obj.number }} de {{ page_obj.paginator.num_pages }} </span>
</li>
{% if page_obj.has_next %}
<li>
<span><a href="?page={{ page_obj.next_page_number }}"> >> </a></span>
</li>
{% endif %}
</ul>
{% else %}
<h3>Your File Exam</h3>
<p>No hay registros para cargar</p>
{% endif %}