Как использовать функцию views в другой функции?

Как я могу использовать функцию view в другой функции?

Я пытаюсь сделать кнопку "Мне нравится", но у меня нет идеи, как я могу получить это.

Первая функция:

def LikeView(request, pk):
    moje_posty = get_object_or_404(Posty, id=request.POST.get('post_id'))

    if moje_posty.likes.filter(id=request.user.id).exists():
        moje_posty.likes.remove(request.user.id)
    else:
        moje_posty.likes.add(request.user.id)
    return HttpResponseRedirect(reverse('home:detail_post', args=[str(pk)]))

Вторая функция:

def contact(request, pk):
    template_name = 'detail_post_view.html'
    post = get_object_or_404(Posty, pk=pk)
    comment = CommentPost.objects.all().filter(post=post.id).order_by('-date_posted')[:10]
    new_comment = True
    profil = Profil.objects.get(user=request.user)

    if request.method == "POST":
        comment_form = CommentModelForm(request.POST or None)
        if comment_form.is_valid():
            instance = comment_form.save(commit=False)
            instance.user = profil

            new_comment = comment_form.save(commit=False)
            new_comment.post = post
            comment_form.save()
            comment_form = CommentModelForm()
    else:
        comment_form = CommentModelForm(request.POST or None)

    context = {
        'post': post,
        'new_comment': new_comment,
        'comment_form': comment_form,
        'comment': comment,
    }

    return render(request, template_name, context)

Как я могу использовать это в своем шаблоне?

Вернуться на верх