user = models.ForeignKey(User, related_name="votes")\r
node = models.ForeignKey(Node, related_name="votes")\r
value = models.SmallIntegerField()\r
- action = models.ForeignKey(Action, unique=True, related_name="vote")\r
+ action = models.OneToOneField(Action, related_name="vote")\r
voted_at = models.DateTimeField(default=datetime.datetime.now)\r
\r
class Meta:\r
user = models.ForeignKey(User, related_name="flags")\r
node = models.ForeignKey(Node, related_name="flags")\r
reason = models.CharField(max_length=300)\r
- action = models.ForeignKey(Action, unique=True, related_name="flag")\r
+ action = models.OneToOneField(Action, related_name="flag")\r
flagged_at = models.DateTimeField(default=datetime.datetime.now)\r
\r
class Meta:\r
app_label = 'forum'\r
unique_together = ('user', 'node')\r
\r
-class BadgeManager(models.Manager):\r
- use_for_related_fields = True\r
- \r
+class BadgesQuerySet(models.query.QuerySet):\r
def get(self, *args, **kwargs):\r
try:\r
pk = [v for (k,v) in kwargs.items() if k in ('pk', 'pk__exact', 'id', 'id__exact')][0]\r
except:\r
- return super(BadgeManager, self).get(*args, **kwargs)\r
+ return super(BadgesQuerySet, self).get(*args, **kwargs)\r
\r
from forum.badges.base import BadgesMeta\r
badge = BadgesMeta.by_id.get(int(pk), None)\r
if not badge:\r
- return super(BadgeManager, self).get(*args, **kwargs)\r
+ return super(BadgesQuerySet, self).get(*args, **kwargs)\r
return badge.ondb\r
\r
+\r
+class BadgeManager(models.Manager):\r
+ use_for_related_fields = True\r
+\r
+ def get_query_set(self):\r
+ return BadgesQuerySet(self.model)\r
+\r
class Badge(models.Model):\r
GOLD = 1\r
SILVER = 2\r
\r
@models.permalink\r
def get_absolute_url(self):\r
- return ('badge', [], {'id': self.id, 'slug': slugify(self.name)}) \r
+ return ('badge', [], {'id': self.id, 'slug': slugify(self.name)})\r
+\r
+ def save(self, *args, **kwargs):\r
+ if isinstance(self.awarded_count, models.expressions.ExpressionNode):\r
+ super(Badge, self).save(*args, **kwargs)\r
+ self.awarded_count = self.__class__.objects.filter(id=self.id).values_list('awarded_count', flat=True)[0]\r
+ else:\r
+ super(Badge, self).save(*args, **kwargs)\r
+\r
\r
class Meta:\r
app_label = 'forum'\r
awarded_at = models.DateTimeField(default=datetime.datetime.now)\r
\r
trigger = models.ForeignKey(Action, related_name="awards", null=True)\r
- action = models.ForeignKey(Action, related_name="award", unique=True)\r
+ action = models.OneToOneField(Action, related_name="award")\r
\r
\r
class Meta:\r