def user_evidence(request, userid): cursor = connection.cursor() cursor.execute('SELECT \ user_id, \ content_id,\ mov.title,\ count(case when event = \'buy\' then 1 end) as buys,\ count(case when event = \'details\' then 1 end) as details,\ count(case when event = \'moredetails\' then 1 end) as moredetails\ FROM \ public."evidenceCollector_log" log\ JOIN public.movies mov \ ON CAST(log.content_id AS VARCHAR(50)) = CAST(mov.id AS VARCHAR(50))\ WHERE\ user_id = \'%s\'\ group by log.user_id, log.content_id, mov.title\ order by log.user_id, log.content_id' % userid) data = dictfetchall(cursor) movie_ratings = Builder.generate_implicit_ratings(data) Builder.save_ratings(userid, movie_ratings) return JsonResponse(movie_ratings, safe=False)