I am learning Django by working on a baseball stats tracking
application. In it, I have a Team model, like this:

class Team(models.Model):
    name = models.CharField(maxlength=200)

Teams participate in games (in a Game model), either as the home team
or the visiting team. I have a method in the Team model which
calculates the team's record (wins/losses/ties). I want to have show
(and sort by) the team's "winning percentage" (one point per win, 0.5
points per tie, 0 points for a loss - divided by the number of games
played). I have a win_percentage() method defined for the model, but
I'm at a loss for how to sort by it for views/templates.

Since the method doesn't correspond to a column in a table, the
order_by() method doesn't work. I want to show all teams by descending
winning percentage in a "standings" view, but I'm not sure what way to
best accomplish this. I have ideas in my head about iterating over the
Team.objects.all() and creating some kind of dict with that information
in it, but that seems a little counter-intuitive.

Has anyone solved this in the past, or is there someplace in the
documentation which might help?

H.B.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to