Order Model by Dependent Field
<p>I have 2 models, PlayerPick and Game. PlayerPick has a foreign key to the game model, showing which game the pick is for. If I want to order all of the picks by the game time, what would be the best way to do so? Is there a way to automatically add the gameTime field to the player pick model? Please see the code below</p>

<pre><code>class PlayerPick(models.Model):
    player_profile = models.ForeignKey('PlayerProfile')
    team = models.ForeignKey('Team')

class Game(models.Model):
    team1 = models.ForeignKey('Team', related_name="game_set_team1")
    team2 = models.ForeignKey('Team', related_name="game_set_team2")
    time = models.DateTimeField(null=True, blank=True)
</code></pre>

<pre><code>class PlayerPick(models.Model):
    player_profile = models.ForeignKey('PlayerProfile')
    team = models.ForeignKey(Game)

class Game(models.Model):
    team1 = models.ForeignKey('Team', related_name="game_set_team1")
    team2 = models.ForeignKey('Team', related_name="game_set_team2")
    time = models.DateTimeField(null=True, blank=True)
</code></pre>

<p>You can do it like so</p>

<pre><code>PlayerPick.objects.all().order_by(team = Game.objects.all().order_by('time'))
</code></pre>

<p>But you can always define a custom model Manager that if you will access that query regularly it will make your life easier. Please check:
<a href="http://blog.kevinastone.com/django-model-behaviors.html" rel="nofollow">http://blog.kevinastone.com/django-model-behaviors.html</a></p>

python django order field models