title: How to efficiently store a ranked list of objects in Django?
body: <p>I have a Django Model:</p>
  
  <pre><code>from django.db import models
  
  class Player(models.Model):
      name = models.CharField(max_length=254, null=True, blank=True,)
      score = models.IntegerField()
  
  A = Player.create(name="A", score=99)
  B = Player.create(name="B", score=66)
  C = Player.create(name="C", score=66)
  D = Player.create(name="D", score=55)
  E = Player.create(name="E", score=44)
  </code></pre>
  
  <p>I want to maintain a ranking of all my players by score. If players have the same score, they will have the same rank. So in this case, the ranking would look like this:</p>
  
  <pre><code>Name       Score     Rank
  A          99        1
  B          66        2
  C          66        2
  D          55        4
  E          44        5
  </code></pre>
  
  <p>I want to store this ranking in the Database so that I don't constantly have to perform expensive sorting queries. I need to efficiently perform all the following operations:</p>
  
  <ol>
  <li>Given a player, lookup their rank</li>
  <li>Given a rank, find out which player(s) have that rank</li>
  <li>Given a player, insert them into this ranking</li>
  <li>Given a player, delete them from this ranking</li>
  <li>Given a player and a score, update their position in this ranking</li>
  </ol>
  
  <p>I will need to insert and delete players from this list. Whenever I do #3, #4 or #5, I will need to update the ranks of other players accordingly to maintain the integrity of the ranking. </p>
  
  <p>What is the most efficient way to do so in Django? How do I build my models so this will work efficiently and my database operations will be minimal? Please show me what any new models should look like.</p>