0

So I'm attempting to implement the pagination for a website that i'm working on, but it seems not to work completely.

class ExampleListView(FormMixin, ListView):
    model = Example
    template_name = "example.html"
    paginate_by = 3
    context_object_name = "example_list"
    allow_empty = True
    page_kwarg = 'page'
    paginate_orphans = 0
    form_class = ExampleForm

Then in the html I have the following

 <tbody>
          {% for formset_form in formset %}
          ...
          {% endfor %}
...

 {% if is_paginated %}
        <div class="pagination">
            <span class="page-links">
                {% if page_obj.has_previous %}
                    <a href="{{request.path}}?page={{ page_obj.previous_page_number }}">Previous</a>
                {% endif %}
                <span class="page-current">
                    Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}
                </span>
                {% if page_obj.has_next %}
                    <a href="{{request.path}}?page={{ page_obj.next_page_number }}">Next</a>
                {% endif %}
            </span>
        </div>
{% else %}
    <p></p>
{% endif %}

I currently have 5 forms there in the table, and paginated it by 3. What it does is that is displays Page 1 of 2 Next, like it should, but it displays all of the forms on the pages.

dnsko
  • 1,017
  • 4
  • 17
  • 29

1 Answers1

0

The Django ListView is meant to render 'A page representing a list of objects.'. You try to display a paginated list of formsets. Interesting thought, but not what ListView does.

This answer to a previous question may help you to achieve what you want.

Community
  • 1
  • 1
Jieter
  • 4,101
  • 1
  • 19
  • 31
  • Ah I understand. Someone else set up this project so I overlooked it. Any suggestions though to get the result I'd like? A different view perhaps? – dnsko May 31 '16 at 11:01
  • @dnsko Added a pointer to another question, but I think it's going to be a bit more complicated than your original example. – Jieter May 31 '16 at 11:07