def add_review(request, company_id): company = get_object_or_404(Company, pk=company_id) form = ReviewForm(request.POST) if form.is_valid(): rating = form.cleaned_data['rating'] comment = form.cleaned_data['comment'] user_name = form.cleaned_data['user_name'] review = Review() review.company = company 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('reviews:company_detail', args=(company.id,))) return render(request, 'reviews/company_detail.html', {'company': company, 'form': form})