Exemplo n.º 1
0
def rate_merchant(request, merchant_id):
    if request.method == 'POST':
        rating_form = RatingForm(data=request.POST)
        if rating_form.is_valid():
            # rating_form.user = get_object_or_404(User, pk=request.user.id)
            # rating_form.merchant = get_object_or_404(Merchant, pk=merchant_id)
            merchant = get_object_or_404(Merchant, pk=merchant_id)
            rating = MerchantRating(user=get_object_or_404(User, pk=request.user.id), merchant=merchant)
            rating.rating_ontime = request.POST['rating_quality']
            rating.rating_quality = request.POST['rating_quality']
            rating.rating_reliability = request.POST['rating_ontime']
            rating.rating_value = request.POST['rating_quality']
            rating.save()
            ratings = MerchantRating.objects.all().filter(merchant=merchant)
            context = {"merchant": rating.merchant, "ratings": ratings}
            return render(request, 'hackathon/merchant.html', context)
        else:
            print rating_form.errors
    else:
        rating_form = RatingForm()

    merchant = get_object_or_404(Merchant, pk=merchant_id)
    return render(request,
                  'hackathon/rate_merchant.html',
                  {'rating_form': rating_form, 'merchant': merchant})
Exemplo n.º 2
0
r7 = MerchantRating(merchant=m7, user=u7)
r8 = MerchantRating(merchant=m8, user=u8)
r9 = MerchantRating(merchant=m9, user=u9)
r10 = MerchantRating(merchant=m10, user=u10)
r11 = MerchantRating(merchant=m11, user=u11)
r12 = MerchantRating(merchant=m12, user=u12)
r13 = MerchantRating(merchant=m13, user=u13)
r14 = MerchantRating(merchant=m14, user=u14)
r15 = MerchantRating(merchant=m15, user=u15)
r16 = MerchantRating(merchant=m16, user=u16)
r17 = MerchantRating(merchant=m17, user=u17)
r18 = MerchantRating(merchant=m18, user=u18)
r19 = MerchantRating(merchant=m19, user=u19)
r20 = MerchantRating(merchant=m20, user=u20)

r1.save()
r2.save()
r3.save()
r4.save()
r5.save()
r6.save()
r7.save()
r8.save()
r9.save()
r10.save()
r11.save()
r12.save()
r13.save()
r14.save()
r15.save()
r16.save()