Mercurial > public > sg101
diff gpp/downloads/models.py @ 192:341759e1cda1
Implementing #67: use a denormalized count field on download categories to reduce database queries.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 03 Apr 2010 01:10:00 +0000 |
parents | 0e4961833cdf |
children | b4305e18d3af |
line wrap: on
line diff
--- a/gpp/downloads/models.py Thu Apr 01 02:01:33 2010 +0000 +++ b/gpp/downloads/models.py Sat Apr 03 01:10:00 2010 +0000 @@ -15,6 +15,7 @@ """Downloads belong to categories.""" title = models.CharField(max_length=64) description = models.TextField(blank=True) + count = models.IntegerField(default=0, blank=True) class Meta: verbose_name_plural = 'Categories' @@ -23,9 +24,6 @@ def __unicode__(self): return self.title - def num_downloads(self): - return Download.public_objects.filter(category=self.pk).count() - def download_path(instance, filename): """ @@ -114,7 +112,7 @@ vote_date = models.DateTimeField(auto_now_add=True) def __unicode__(self): - return "%s voted on '%s' on %s" % ( + return u"%s voted on '%s' on %s" % ( self.user.username, self.download.title, self.vote_date.strftime('%b %d, %Y %H:%M:%S'))