tags:

views:

39

answers:

1

http://pastebin.com/Aa5rJxv8

i have django problem above, i tried to explain i need to show ratings given by current user to books in user shelves

thanks

+1  A: 

One way to do this in the template would be to define a custom filter. This custom filter can accept a queryset and the currently logged in user as arguments and do the necessary filtering.

@register.filter
def filter_by_user(queryset, user):
    """Filter the queryset by (currently logged in) user"""
    return queryset.filter(added_by = user)

And in the template:

<td>{{ book.rating_set.all|filter_by_user:user|safeseq|join:", " }}</td>
Manoj Govindan
thanks for this great solution :) i'am the happy man now :)
soField
@soField: happy to help :)
Manoj Govindan