def rate(request, project_id, rate): p=Project.objects.get(id=project_id) user=User.objects.get(login=request.session['login']) r=Rating() r.rating=rate r.user=user r.project=p r.save() try: rates=Rating.objects.filter(Q(project__id=int(p.id))) except: rates=None j=int(rates.__len__()) rating=0 for rate in rates: rating+=rate.rating if j!=0: rating = rating/j rating = int(rating) html='Ocena:<nobr>' for i in range(1,6): if i>int(rating): print(i) html += '<img width=\"20\" height=\"20\" src=\"/static/emptystarr.png\" >' else: print(i) html += '<img width=\"20\" height=\"20\" src=\"/static/fillstar.jpg\" >' html+='</nobr><br>' print(html) return HttpResponse(html)