title: last record in django models database
body: <p>i am trying to do this: </p>
  
  <p>i have a table of rating records of locations. in this table, one location can also have multiple rating scores. but i want to restrict the search only to the last record of same locations. for example: </p>
  
  <p>one location with <code>id</code>=1 has 3 rating scores: 1, 2, 4. now when user searchs for rating score 2, this location should <strong>NOT</strong> appear, because its last record is 4.   </p>
  
  <p><strong>EDIT</strong><br>
  there are two tables(django models): location and rating. </p>
  
  <p>can i do this: </p>
  
  <pre><code>all_locations = Location.objects.all()
  </code></pre>
  
  <p>then in template. <code>locations_rating</code> is a related_name for foreignkey <code>locationID</code> in rating table. </p>
  
  <pre><code>{% for location in all_locations %}
    {{ location.locations_rating }}
  {% endfor %}
  </code></pre>