if request.method == 'POST':
review_form = RatingForm(request.POST)
# how do I do proper form validation in a func based view?
# If I do it witha CBV the invalid form will reload the page and add
# a specific error message on the invalid fields.
if not review_form.is_valid():
messages.error(request, 'Form was not valid. Please try again.')
if existing_rating:
existing_rating.score = review_form.cleaned_data['score']
existing_rating.comment = review_form.cleaned_data['comment']
existing_rating.save()
return redirect('tutor_detail', pk=pk)
review = review_form.save(commit=False)
review.tutor = tutor
review.user = request.user
review.save()
messages.success(request, 'Review added successfully.')
return redirect('tutor_detail', pk=pk)