# HG changeset patch # User Brian Neal # Date 1306010102 0 # Node ID ac9217eef6104c4a605372d123e495017dcda2f3 # Parent 1f139de929c4a12c4eaabfbf9497a3d7e0dc27c9 Added total vote information to the poll templates. Cache the total votes in the model instance. diff -r 1f139de929c4 -r ac9217eef610 gpp/polls/models.py --- a/gpp/polls/models.py Sat May 21 19:55:48 2011 +0000 +++ b/gpp/polls/models.py Sat May 21 20:35:02 2011 +0000 @@ -68,12 +68,16 @@ return (total_votes, choices) - def total_votes(self): + def _total_votes(self): """ Returns the number of votes cast in this poll to date. """ - return sum(choice.votes for choice in self.choice_set.all()) + if not hasattr(self, '_total_votes_cache'): + self._total_votes_cache = sum(choice.votes for choice in + self.choice_set.all()) + return self._total_votes_cache + total_votes = property(_total_votes) def is_open(self): now = datetime.datetime.now() diff -r 1f139de929c4 -r ac9217eef610 gpp/templates/polls/index.html --- a/gpp/templates/polls/index.html Sat May 21 19:55:48 2011 +0000 +++ b/gpp/templates/polls/index.html Sat May 21 20:35:02 2011 +0000 @@ -8,6 +8,7 @@