X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/b8f3a2323d03384198863e35d6467a8624a2e31a..b6f6103a8b578d13047219ef3812cea09001eea2:/forum/models/meta.py diff --git a/forum/models/meta.py b/forum/models/meta.py index 53d4c49..fca763f 100644 --- a/forum/models/meta.py +++ b/forum/models/meta.py @@ -5,7 +5,7 @@ class Vote(models.Model): user = models.ForeignKey(User, related_name="votes") node = models.ForeignKey(Node, related_name="votes") value = models.SmallIntegerField() - action = models.ForeignKey(Action, unique=True, related_name="vote") + action = models.OneToOneField(Action, related_name="vote") voted_at = models.DateTimeField(default=datetime.datetime.now) class Meta: @@ -17,28 +17,33 @@ class Flag(models.Model): user = models.ForeignKey(User, related_name="flags") node = models.ForeignKey(Node, related_name="flags") reason = models.CharField(max_length=300) - action = models.ForeignKey(Action, unique=True, related_name="flag") + action = models.OneToOneField(Action, related_name="flag") flagged_at = models.DateTimeField(default=datetime.datetime.now) class Meta: app_label = 'forum' unique_together = ('user', 'node') -class BadgeManager(models.Manager): - use_for_related_fields = True - +class BadgesQuerySet(models.query.QuerySet): def get(self, *args, **kwargs): try: pk = [v for (k,v) in kwargs.items() if k in ('pk', 'pk__exact', 'id', 'id__exact')][0] except: - return super(BadgeManager, self).get(*args, **kwargs) + return super(BadgesQuerySet, self).get(*args, **kwargs) from forum.badges.base import BadgesMeta badge = BadgesMeta.by_id.get(int(pk), None) if not badge: - return super(BadgeManager, self).get(*args, **kwargs) + return super(BadgesQuerySet, self).get(*args, **kwargs) return badge.ondb + +class BadgeManager(models.Manager): + use_for_related_fields = True + + def get_query_set(self): + return BadgesQuerySet(self.model) + class Badge(models.Model): GOLD = 1 SILVER = 2 @@ -86,7 +91,7 @@ class Award(models.Model): awarded_at = models.DateTimeField(default=datetime.datetime.now) trigger = models.ForeignKey(Action, related_name="awards", null=True) - action = models.ForeignKey(Action, related_name="award", unique=True) + action = models.OneToOneField(Action, related_name="award") class Meta: