Django Lazy Loading Pagination

I am trying to use Django Endless Pagination to achieve the pag tag () effect when the user scrolls to the bottom of the page, then the new content is uploaded to the page. Using the above module, I was able to do this. However, I have a performance issue. The view from where I am sending the data still loads all the rows from the database. Only on the side of the template is part of it displayed.

class IndexView(BaseAjaxViewList):
    template_name = 'polls/index.html'
    page_template = 'polls/item_index.html'
    context_object_name = 'data'
    model = Question

    def get_context_data(self,**kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)
        print(len(context["data"]))
        return context

I thought that only the “n” number of elements would be available from the database, and when scrolling, another db call would occur, etc., which could improve page loading performance. Suppose there are 1000 elements on a page, then ideally I would like, say, 50 elements to load first (50 elements to access a 1 dB call), and then when the user scrolls to the bottom of the page, then 50 elements must be accessible and displayed. However, I tried to check under the stage, and it seems that all 1000 calls are made immediately using this module. Only from the side of the template at the same time 50 are displayed. Is this true? Is there any django module that will do this, or will I have to write my own ajax calls, etc.?

Below are the templates for the link:

Main template

 <h2>Polls:</h2>
    {% include page_template %}

    {% block js %}
        {{ block.super }}
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script src="{% static 'endless_pagination/js/endless-pagination.js' %}"></script>
        <script>$.endlessPaginate();</script>
    {% endblock %}

page_template:

{% load endless %}

{% paginate entries %}
{% for entry in entries %}
    {# your code to show the entry #}
{% endfor %}
{% show_more %}
+4
1

Django Ajax Ajax Django. , . 50 ( , ), . Ajax.

- :

@django_ajax
def paginated_cache(request):
    more_results = [cache.get('your_results').pop() for result in range(50)]
    # turn this to json, wrap in dictionary and return

django ajax. . - .

+1

All Articles