Hi, Just guessing, but if I understood well the error you get, that's normal.
The KarmaScoreManager is not the amount of karma of a coment (or in your case an object). It keeps in the database the karma score that a given user gave to a specific comment (or object). As there is a single score per user and per object, you can only override the total karma. The key point of the calculation of the karma is in the Comment model: def _fill_karma_cache(self): "Helper function that populates good/bad karma caches" good, bad = 0, 0 for k in self.karmascore_set.all(): if k.score == -1: bad +=1 elif k.score == 1: good +=1 self._karma_total_good, self._karma_total_bad = good, bad For a given Comment, the function of the model will take all the KarmaScore for the given comment (self.karmascore_set.all()) and iterate over them to calculate the total karma of the Comment (self). If you want to do a generic karma, you might want to add a function to the manipulator that will do just this, take an id and content_type, get() the object, find all the KarmaScores that are related to this object (self.karmascore_set.all()) and calculate the total karma by iterating over those. Hope it helps, G On 10/30/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > 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 -~----------~----~----~----~------~----~------~--~---