2011-09-09 11 views
0

3つの別々のカテゴリに統計情報を集めたいプレイヤーのリストがあります。 (ラッシング、パッシング、レシービング)。DJangoでデータを追加してJOINテーブルを追加するには

毎週プレーヤーが各カテゴリの新しい統計情報を取得します。

私ができることを望むのは、特定の統計に最も多くのヤードを持つ人が注文した各カテゴリの上位5人の選手をリストすることです。私はviews.pyファイルにクエリを設定する方法やdjangoのテンプレートファイル内で何かを行う必要があるかどうかはよく分かりません。ここで

は私のモデルがどのように見えるかです:

class Player(models.Model): 

    first_name = models.CharField(
     max_length = 100, 
     verbose_name = "First Name" 
     ) 
    last_name = models.CharField(
     max_length = 100, 
     verbose_name = "Last Name" 
     ) 
    position = models.CharField(
     max_length = 2, 
     choices = (('QB', 'QB',), ('RB', 'RB',), ('WR', 'WR',),), 
     blank = True 
     ) 
    team = models.CharField(
     max_length = 30, 
     choices = (('Dallas', 'Dallas',), ('New York', 'New York',), ('Tampa Bay', 'Tampa Bay',),), 
     blank = True 
     ) 
    number = models.CharField(
     max_length = 3, 
     blank = True 
     ) 

class PlayerStat(models.Model): 
    player = models.ForeignKey(Player) 

    week_num = models.CharField(
     max_length = 10, 
     choices = (('1', 'Sep 2nd',), ('2', 'Sep 9th',), ('3', 'Sep 16th',),('4', 'Sep 23rd',), ('5', 'Sep 30th',), ('6', 'Nov 2nd',),('7', 'Nov 7th',), ('8', 'Nov 14th',), ('9', 'Nov 21st',),('10', 'Nov 28th',), ('11', 'Dec 4th',), ('12', 'Dec 11th',),), 
     blank = True, 
     null=True 
     ) 
    rushing_attempts = models.CharField(
     max_length = 100, 
     verbose_name = "Rushing Attempts", 
     blank=True 
     ) 
    rushing_yards = models.CharField(
     max_length = 100, 
     verbose_name = "Rushing Yards", 
     blank=True 
     ) 
    rushing_touchdowns = models.CharField(
     max_length = 100, 
     verbose_name = "Rushing Touchdowns", 
     blank=True 
     ) 
    passing_attempts = models.CharField(
     max_length = 100, 
     verbose_name = "Passing Attempts", 
     blank=True 
     ) 
    passing_completions = models.CharField(
     max_length = 100, 
     verbose_name = "Passing Completions", 
     blank=True 
     ) 
    passing_yards = models.CharField(
     max_length = 100, 
     verbose_name = "Passing Yards", 
     blank=True 
     ) 
    passing_touchdowns = models.CharField(
     max_length = 100, 
     verbose_name = "Passing Touchdowns", 
     blank=True 
     ) 
    receptions = models.CharField(
     max_length = 100, 
     verbose_name = "Receptions", 
     blank=True 
     ) 
    receiving_yards = models.CharField(
     max_length = 100, 
     verbose_name = "Receiving Yards", 
     blank=True 
     ) 
    receiving_touchdowns = models.CharField(
     max_length = 100, 
     verbose_name = "Receiving Touchdowns", 
     blank=True 
     ) 

私は、PythonとDjangoへのnoobですので、任意の助けをいただければ幸いです。

おかげで、すべての

答えて

1

まず、私はあなたがそれぞれのstatトップ5のクエリを統計情報のためのDecimalFieldを使用するためにモデルを変更して する必要があります。

PlayerStat.objects.order_by('receiving_yards')[:5] 

あなたはまた、順序を与えることができます注文するフィールドを複数リストにする

PlayerStat.objects.order_by('receiving_yards,receptions,receiving_touchdowns')[:5] 
関連する問題