Search code examples
pythondjangopaginationdjango-endless-pagination

Doesn't calling Entry.object.all() defeat the point of Django endless pagination?


On https://django-endless-pagination.readthedocs.org/en/latest/twitter_pagination.html I'm reading that the example views.py might look like this:

from endless_pagination.decorators import page_template

@page_template('myapp/entry_index_page.html')  # just add this decorator
def entry_index(
        request, template='myapp/entry_index.html', extra_context=None):
    context = {
        'entries': Entry.objects.all(),
    }
    if extra_context is not None:
        context.update(extra_context)
    return render_to_response(
        template, context, context_instance=RequestContext(request))

This seems to indicate that we must call Entry.objects.all() and pass the results to the template. But doesn't Entry.objects.all() already make the query call to retrieve all the corresponding DB objects, defeating one of the main objectives of pagination (to retrieve small chunks of data at a time)?


Solution

  • Queries in Django are Lazy, that means that Entry.objects.all() does not bring the complete list of Entries, it just specifies the scope of the results Endless will show.