def homePost(request, text_id): github_login, twitter_login, facebook_login, google_login = get_account( request) if request.method == 'POST': innput = get_object_or_404(Input, pk=text_id) temp_accuracy = 0.0 total = innput.happy + innput.sad + innput.stupefied + innput.angry + innput.others + 1 if request.POST.get('expression') == "1": innput.happy += 1 temp_accuracy = innput.happy / total elif request.POST.get('expression') == "2": innput.sad += 1 temp_accuracy = innput.sad / total elif request.POST.get('expression') == "3": innput.stupefied += 1 temp_accuracy = innput.stupefied / total elif request.POST.get('expression') == "4": innput.angry += 1 temp_accuracy = innput.angry / total elif request.POST.get('expression') == "5": innput.others += 1 temp_accuracy = innput.others / total innput.save() user = User.objects.get(pk=request.user.pk) record = Record.objects.filter(user=request.user) print("RECORD:::: ") print(record) if not record: record = Record(user=user) record.save() record = Record.objects.get(user_id=user.id) record.total_tags += 1 record.total_accuracy = Decimal( record.total_accuracy) + Decimal(temp_accuracy) record.accuracy = Decimal(record.total_accuracy) / Decimal( record.total_tags) record.accuracy = Decimal(record.accuracy) * Decimal(100.0) record.save() else: pass random_text = Input.objects.order_by('?')[0] return render( request, 'index.html', { 'texts': random_text, 'github_login': github_login, 'twitter_login': twitter_login, 'facebook_login': facebook_login, 'google_login': google_login })