Permalink
Browse files

added UserPostCount.calculate

  • Loading branch information...
1 parent 796eb42 commit 8a8031eae11c5198ae9295d27710d3505f077509 @brosner brosner committed Feb 3, 2011
Showing with 15 additions and 1 deletion.
  1. +14 −0 agora/models.py
  2. +1 −1 setup.py
View
14 agora/models.py
@@ -307,6 +307,20 @@ class UserPostCount(models.Model):
user = models.ForeignKey(User, related_name="post_count")
count = models.IntegerField(default=0)
+
+ @classmethod
+ def calculate(cls):
+ for user in User.objects.all():
+ count = ForumReply.objects.filter(author=user).count()
+ upc, created = cls._default_manager.get_or_create(
+ user = user,
+ defaults = dict(
+ count = count
+ )
+ )
+ if not created:
+ upc.count = count
+ upc.save()
class ThreadSubscription(models.Model):
View
2 setup.py
@@ -3,7 +3,7 @@
setup(
name = "agora",
- version = "0.1.dev10",
+ version = "0.1.dev11",
author = "Eldarion",
author_email = "development@eldarion.com",
description = "an extensible forum app for Django and Pinax",

0 comments on commit 8a8031e

Please sign in to comment.