def show_pet_detail(req, pk): pet = Pet.objects.get(pk=pk) pet.likes_count = pet.like_set.count() if req.method == 'GET': return render(req, 'pets/pet_detail.html', get_detail_context(req, pet)) elif req.method == 'POST': form = CommentForm(req.POST) if form.is_valid(): comment = Comment(comment=form.cleaned_data['comment']) comment.pet = pet comment.user = req.user.userprofile # do not link to profile but user comment.save() pet.comment_set.add(comment) pet.save() # new_comment = Comment(pet=pet, comment=req.POST['comment']) # new_comment.save() # pet.comment_set.add(new_comment) return redirect('pet_details', pet.id)