def addComment(request, id): if request.method != 'POST': return HttpResponseBadRequest("Wrong method") if not request.user.is_authenticated(): resp = addToTemplate(request, 'Necesitas estar registrado') return HttpResponse(resp) try: act = Activity.objects.get(id = id) form = CommentForm(request.POST) form.nick = request.user.username if form.is_valid(): text = form.cleaned_data['text'] comment = Comment(nick = request.user.username, text = text) comment.save() act.comments.add(comment) return HttpResponseRedirect('/actividad/' + str(id)) except Activity.DoesNotExist: resp = addToTemplate(request, 'La actividad no existe') return HttpResponse(resp)