私は持っていmodels.py
ます:
class Team(models.Model):
x = models.IntegerField()
y = models.IntegerField()
a = models.IntegerField()
b = models.IntegerField()
def get_stat(self):
return {
'xy': self.x + self.y,
'ab': self.a + self.b
}
stat = property(get_stat)
私team.html
が持っている:
xy stat: {{ team.stat.xy }}
ab stat: {{ team.stat.ab }}
問題は、「djangoは、get_stat
呼び出すたびに関数を実行するのstat
か、それとも結果をキャッシュするのか」ということです。