def add_review(request, game_id): game = get_object_or_404(Game, pk=game_id) form = ReviewForm(request.POST) if form.is_valid(): rating = form.cleaned_data['rating'] comment = form.cleaned_data['comment'] user_name = request.user.username review = Review() review.game = game review.user_name = user_name review.rating = rating review.comment = comment review.pub_date = datetime.datetime.now() review.save() """Always return an HttpResponseRedirect after successfully dealing with POST data. This prevents data from being posted twice if a user hits the Back button.""" return HttpResponseRedirect(reverse('game_detail', args=(game.id,))) return render(request, 'game_detail.html', {'game': game, 'form': form})
def add_review(request, game_id): game = get_object_or_404(Game, pk=game_id) form = ReviewForm(request.POST) if form.is_valid(): rating = form.cleaned_data['rating'] comment = form.cleaned_data['comment'] user_name = request.user.username review = Review() review.game = game review.user_name = user_name review.rating = rating review.comment = comment review.pub_date = datetime.datetime.now() review.save() """Always return an HttpResponseRedirect after successfully dealing with POST data. This prevents data from being posted twice if a user hits the Back button.""" return HttpResponseRedirect(reverse('game_detail', args=(game.id, ))) return render(request, 'game_detail.html', {'game': game, 'form': form})