On May 27, 3:10 pm, Pirate Pete <peters.stay...@gmail.com> wrote: > hello again, > > i am trying to get a single entry from my db and then annotate the > count and rating to it like we established above > > however it doesn't seem to be returning anything: > videos = > Video.objects.get(id=vid_id).annotate(rating_count=Count('rating'), > rating_avg=Avg('rating__rating'))
The trouble is that .get() directly returns an instance, not a queryset - so you can't call annotate() on it. It should work if you move the .get() clause to the end. > i even tried a filter: > > videos = > Video.objects.all().filter(id=vid_id).annotate(rating_count=Count('rating') , > rating_avg=Avg('rating__rating')) > > this is really puzzling me as to why it is not working. Any ideas? This should work, although remember that it will return a single-item queryset, rather than a single instance as above - so you'll still need to iterate through, or slice it (via videos[0]). > Also i seem to be getting an error with my |drawstars which works fine > on other pages that dont require this individual selection. > > I don't quite understand this error: > > "Caught an exception while rendering: a float is required" > > thanks in advance That's probably because you're passing the queryset, rather than individual instance, as I note above. You should be seeing error tracebacks, especially in the first example you show above - you should find they are helpful in debugging this sort of thing. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.