Hi!
I have the following models:

class Player(models.Model):
    name = models.CharField('Name', max_length=40)
    pub_date = models.DateTimeField('date added', 
default=datetime.datetime.now)
    def __unicode__(self):
        return self.name
    def goals(self):
        g = 0
        ms1 = Match.objects.filter(opp1=self)
        ms2 = Match.objects.filter(opp2=self)
        for m in ms1:
            g += m.opp1_goals
        for m in ms2:
            g += m.opp2_goals
        return g

class Match(models.Model):
    opp1 = models.ForeignKey(Player)
    opp2 = models.ForeignKey(Player)
    opp1_goals = models.IntegerField("Goals P1")
    opp2_goals = models.IntegerField("Goals P2")
    pub_date = models.DateTimeField('date published', 
default=datetime.datetime.now)

The problem is when I want to display a statistics overview with all 
players there will be 2 DB-Queries per player only to get the "goals" 
property.
And I got more "calculated fields" like number of won matches, number of 
lost matches, etc...
There are 364 Match entries and 46 Players.
At my overview page I got over 2000 SQL queries which take over 6 seconds 
to load the page.

How can I speed up the process?
I don't want to save those "calculated values" in the database.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/RsK3HmYOBBwJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to