title: Django pagination is not working properly with very large dataset
body: <p>When I use pagination with a very large dataset, it works too slow. Maybe I am not implementing it properly. Please help. How to make it fast? Is there anything that I can change or implement so that it works fine?</p>
  
  <blockquote>
    <p>view.py</p>
  </blockquote>
  
  <pre><code>def display(request):
      user_list = Final.objects.all()
      searchlen= user_list.count()
      paginator = Paginator(user_list, 100)
      page = request.GET.get('page')
      users = paginator.get_page(page)
      return render(request,'displayLogs.html',{'users': users,'searchlen':searchlen})
  </code></pre>
  
  <blockquote>
    <p>model.py</p>
  </blockquote>
  
  <pre><code>class Final(models.Model):
      name = models.TextField(db_column='Date',primary_key=True, blank=True, null=False)  # Field name made lowercase.
      corr = models.TextField(db_column='CorrelationId', blank=True, null=True)  # Field name made lowercase.
  </code></pre>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>      &lt;tbody&gt;
   &lt;tr class="gradeX"&gt;
   {% for item in users %}
   &lt;td&gt;{{item.dat}}&lt;/td&gt;
   &lt;td&gt;{{item.act}}&lt;/td&gt;
   &lt;td&gt;{{item.actor}}&lt;/td&gt;
   &lt;td class="center"&gt;{{item.tar}}&lt;/td&gt;
   &lt;/tr&gt;
         
   {% endfor %}
  &lt;/tbody&gt;
  
  
  &lt;div class="pagination" style="border-style:inset;border-width:5px;padding-bottom: 5px"&gt;
   {% if users.has_previous %}
  
   &lt;a class="pagination-action" href="?page=1"&gt; &lt;i class="fas fa-angle-double-left"&gt;&lt;/i&gt;&lt;/a&gt;
  
   &lt;a class="pagination-action" href="?page={{ users.previous_page_number}}"&gt; &lt;i class="fas fa-angle-left"&gt;&lt;/i&gt;&lt;/a&gt;
  
   {% endif %}
  
   {% for num in users.paginator.page_range %}
    {% if users.number == num %}
  
     &lt;span class="pagination-number pagination-current"&gt;&lt;strong&gt;{{ num }}&lt;/strong&gt;&lt;/span&gt;
  
    {% elif num &gt; users.number|add:'-3' and num &lt; users.number|add:'3' %}
  
    &lt;a class="pagination-number" href="?page={{ num }}"&gt;{{num}}&lt;/a&gt;
  
    {% endif %}
  
   {% endfor %}
  
   {% if users.has_next %}
  
   &lt;a class="pagination-action" href="?page={{ users.next_page_number }}"&gt;&lt;i class="fas fa-angle-right"&gt;&lt;/i&gt;&lt;/a&gt;
   &lt;a class="pagination-action" href="?page={{ users.paginator.num_pages }}"&gt; &lt;i class="fas fa-angle-double-right"&gt; &lt;/i&gt;&lt;/a&gt;
  
   {% endif %}
      
   &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>