Guillermo Fernandez Castellanos wrote:
> 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
>
I thought I had taken care of that. Apparently not. I have:

def _fill_karma_cache(self):
        good, bad = 0, 0
        from django.contrib.contenttypes.models import ContentType
        from gretschpages.karma.models import KarmaScore
        ctype = ContentType.objects.get(model='gpuser')

        for k in KarmaScore.objects.filter(content_type=ctype.id,
object_id=self.id):
            if k.score == -1:
                bad +=1
            elif k.score == 1:
                good +=1
        self._karma_total_good, self._karma_total_bad = good, bad

But something's going awry.


--~--~---------~--~----~------------~-------~--~----~
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