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'))

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?

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


On May 25, 7:58 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On May 25, 10:30 am, Pirate Pete <peters.stay...@gmail.com> wrote:
>
> > sorry for this one last question,
>
> > do you have any idea how i would go about rounding these values and
> > converting them from numbers to *'s ?
>
> > i tried using the round() function on the annotation however it kept
> > giving me a type error "a float is required."
>
> > cheers
>
> I'd probably do a customtemplatefilter:
>
> @register filter
> def stars(value):
>     return '*' * int(round(value))
>
> (you need both int and round, as int always rounds down, so you need
> to do the rounding before converting to int).
>
> Then use it like this (after loading the library in thetemplate):
>     {{ video.rating_avg|stars }}
> --
> 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 
> athttp://groups.google.com/group/django-users?hl=en.

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

Reply via email to