One way to modify it is to modify the variable paginate_by
within the function get_context_data()
but the most recommendable thing is to overwrite the function get_queryset()
in this way:
from django.core.paginator import Paginator
def get_queryset(self,npagina=1):
consulta = Datos.objects.all()
paginacion = Paginator(consulta,'cantidad objetos')
if len(paginacion.page(1)) == 0:
return None
else:
return paginacion.page(npagina)
You must modify your get_context_data to obtain the result and pass it to your template adding this:
context ['data'] = self.get_queryset (npagina = self.request.GET.get ('page'))
And finally add this your tamplate:
{% if is_paginated %}
<ul class="pagination">
{% if datos.has_previous %}
<li>
<span><a href="?page={{ page_obj.previous_page_number }}{% if parametros.urlencode %}&{{ parametros.urlencode }}{% endif %}">Anterior</a></span>
</li>
{% endif %}
<li class="">
<span>Página {{ page_obj.number }} de {{ page_obj.paginator.num_pages }}.</span>
</li>
{% if datos.has_next %}
<li>
<span><a href="?page={{ page_obj.next_page_number }}{% if parametros.urlencode %}&{{ parametros.urlencode }}{% endif %}">Siguiente</a></span>
</li>
{% endif %}
</ul>
{% endif %}
You can modify the function of get_queryset to your liking, it's just an example so you can modify it the way you want