With help from Malcolm, Guillermo and others, I thought I had this
karma thing working. Apparently I do not.

I'm attempting to build my own karma system that will let me allow
voting on anything, not just comments. The problem is, any votes after
the first don't appear to do anything. The previous score is getting
overwritten rather than incremented. This should look pretty familiar
to anyone who's looked at comments:

class KarmaScoreManager(models.Manager):
    def vote(self, user_id, content_type, object_id, rating):
        try:
            karma = self.get(content_type=content_type,
object_id=object_id)
        except self.model.DoesNotExist:
            karma = self.model(None, user_id=user_id,
content_type_id=content_type, object_id=object_id, score=rating,
scored_date=datetime.datetime.now())
            karma.save()
        else:
            karma.score = rating
            karma.scored_date = datetime.datetime.now()
            karma.save()

I think the problem is karma.score = rating, but that's pulled straight
from Comments, which works.

I've tried adding it to itself, both as karma.score = karma.score +
rating or karma.score += rating, but that returns 0

I also tried karma.score += int(rating), but still didn't go.

As with the comment karma system, rating must be 1 or -1

Any ideas?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to