Я хочу сделать функцию ответа на комментарии в Django

У меня есть простой проект, и я добавил в него функцию комментариев. Теперь я хочу добавить функцию ответа на комментарий. Когда я пишу и отправляю ответ, он регистрируется в sql, но я не могу показать его на фронтенде.

models.py

class ReplyComment(models.Model):
reply_comment = models.ForeignKey(Comments, on_delete=models.CASCADE, related_name='replies')
replier_name = models.ForeignKey(User, on_delete=models.CASCADE)
reply_content = models.TextField()
replied_date = models.DateTimeField(auto_now_add=True)

def __str__(self):
    return "'{}' replied with '{}' to '{}'".format(self.replier_name,self.reply_content, self.reply_comment)

views.py

def replyComment(request,id):
comments = Comments.objects.get(id=id)

if request.method == 'POST':
    replier_name = request.user
    reply_content = request.POST.get('reply_content')

    newReply = ReplyComment(replier_name=replier_name, reply_content=reply_content)
    newReply.reply_comment = comments
    newReply.save()
    messages.success(request, 'Comment replied!')
    return redirect('index')

detail.html

<div class="container">
   <a type="text" data-toggle="collapse" data-target="#reply{{comment.id}}" style="float: right;" href="">Reply</a><br>
   {% if replies %}
    {% for reply in replies %}
      <div>
        <div class="fw-bold"><small><b>Name</b></small></div>
        <div style="font-size: 10px;">date</div>
        <small>Reply comment</small><br>
        </div>
     {% endfor %}
    {% endif %}

  <div id="reply{{comment.id}}" class="collapse in">
     <form method="post" action="/article/reply/{{comment.id}}">
        {% csrf_token %}
          <input name="replier_name" class="form-control form-control-sm" type="hidden">
          <input name="reply_content" class="form-control form-control-lg" type="text" placeholder="Reply comment">
          <button type="submit" class="btn btn-primary" style="float: right; margin-top: 5px;">Reply</button>

      </form>
   </div>

Что я пытаюсь сделать, так это вытащить ответы из sql и показать их под комментарием. Я буду рад, если вы подскажете мне решение, подходящее для моих кодов. Спасибо

Возможно, это сработает:

{% for comment in comments %}
    <div>{{ comment }}</div>
        
    {% for reply in comment.replycomment_set.all %}
    <div>
        <div class="fw-bold"><small><b>Name {{ reply.replier_name }}</b></small></div>
        <div style="font-size: 10px;">date {{ reply.replied_date }}</div>
        <small>Reply comment {{ reply.content }}</small><br>
        </div>
    {% endfor %}

{% endfor %}
Вернуться на верх