title: Select the last 3 entry of a model database
body: <p>Hi i have simple question </p>
  
  <p>How can i select only the last 3 entry of a table from a database table ? </p>
  
  <p>I want to display the 3 last news on a news wall but for now i just select all the table and loop only 3 time through the resulting array.</p>
  
  <p>I want to be able to get only the 3 latest news directly with the query (if it's even possible) </p>
  
  <p>Views.py</p>
  
  <pre><code>def accueil(request):
  news=News.objects.order_by('-date')
  return render(request,'dashboard/dashboard.html',{'last_news':news})
  </code></pre>
  
  <p>Template:</p>
  
  <pre><code>{% for news in last_news %}
              {% if forloop.counter &lt; 4 %}
                  &lt;div class="news"&gt;
                      &lt;h3&gt;{{ news.title }}&lt;/h3&gt;
                      &lt;p&gt;{{ news.content|truncatewords_html:80 }}&lt;/p&gt;
                      &lt;p&gt;&lt;a href="{% url "dashboard.views.lireNews" news.id %}"&gt;Lire la suite&lt;/a&gt;&lt;/p&gt;
                  &lt;/div&gt;
           {% endif %}
      {% empty %}
          &lt;p&gt;Aucun news.&lt;/p&gt;
  
      {% endfor %}
       &lt;/div&gt;
  </code></pre>