On Mon, Sep 7, 2009 at 5:45 AM, andreas schmid <a.schmi...@gmail.com> wrote:
> > hi list, > > im experiencing problems with the rating functionality described in the > code sharing site in the practical django projects book: > > if i try to get the score of a snippet with {{ object.get_score }} in > the template i get a result like: > > {'rating__sum': -2} > > > why is that? > > def get_score(self): > return self.rating_set.aggregate(Sum('rating')) > > this is the function i added to my Snippet model > > The results you are getting are correct for the code you show. That function returns the result of an aggregate() call, which returns a dictionary of aggregate values (doc for aggregate is here: http://docs.djangoproject.com/en/dev/ref/models/querysets/#aggregate-args-kwargs), which is exactly what you show being displayed. If you want just the value you'll need to extract it from the dictionary. and the {{ rating.get_rating_display }} doesnt give me any output and no > errors... does anyone know what the problem could be? or does anyone > experieced those problems too and knows the solution for them? > > Since I don't have the book you are working from nor know what the code site is, and you haven't provided the code for get_rating_display I have no idea what it is doing nor why it is failing. If it is using get_score and expecting something other than a dictionary then fixing get_score might fix it, but without checking the book to see what the intent of these functions is supposed to be I'm not really sure of that. Karen --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---