title: How do I get the position of a result in the list after an order_by?
body: <p>I'm trying to find an efficient way to find the rank of an object in the database related to it's score. My naive solution looks like this:</p>
  
  <pre><code>rank = 0
  for q in Model.objects.all().order_by('score'):
    if q.name == 'searching_for_this'
      return rank
    rank += 1
  </code></pre>
  
  <p>It should be possible to get the database to do the filtering, using order_by:</p>
  
  <p>Model.objects.all().order_by('score').filter(name='searching_for_this')</p>
  
  <p>But there doesn't seem to be a way to retrieve the index for the order_by step after the filter.</p>
  
  <p>Is there a better way to do this? (Using python/django and/or raw SQL.)</p>
  
  <p>My next thought is to pre-compute ranks on insert but that seems messy.</p>