コード例 #1
0
def lois_view_detail(request, id):
    """
        Vue detail de la lois
    """
    lois = Lois.objects.get(id=id)
    comments = Comment.objects.filter(lois=id)
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            form = form.save(commit=False)
            form.comment_title = request.user
            form.lois = lois
            form.comment = request.POST['comment']
            form.save()
            return redirect('app:lois-view', id)
    else:
        form = CommentForm()
    context = {
        'lois': lois,
        'comments': comments,
        'form': form,
    }
    template_name = 'pages/lois-view.html'
    return render(request, template_name, context)