i have django problem above, i tried to explain i need to show ratings given by current user to books in user shelves
thanks
i have django problem above, i tried to explain i need to show ratings given by current user to books in user shelves
thanks
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>