title: Django Template Slice - Reversing Order
body: <p>Thanks to a very helpful hint from another question I learned I can limit the amount of values in a list by slicing it in the template as such:</p>
  
  <pre><code>{% for comment in thread.comment_set.all|slice:":3" %}
  </code></pre>
  
  <p>Now I would like to get the last 3 results of my comments so I figured a simple ":-3" or "-3" would do the trick, alas:</p>
  
  <pre><code>Caught an exception while rendering: Negative indexing is not supported.
  </code></pre>
  
  <p>Also using:</p>
  
  <pre><code>{% for comment in thread.comment_set.all|slice:":3" reversed %}
  </code></pre>
  
  <p>Does not do the trick because if I have 5 comments, instead of 1,2,3 it displays the first three in 3,2,1 order.</p>
  
  <p>Is there any way I can display the last 3 comments of a post without going into my database?  I'd love to be able to do this purely using the templating system.</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <pre><code>{% for comment in thread.comment_set.all|dictsortreversed:"created"|slice:"3" %}
  </code></pre>
  
  <p>Displays the last three thanks to my table having the created timestamp.</p>