Как отобразить атрибут модели в таблице в файле am html?

У меня есть проект и модель задач, и я хочу сделать таблицу в детальном html, которая отображает задачи в проекте.

Я пробовал делать

<table>
     <tr>
         <th>Name</th>
         <th>Assignee</th>
         <th>Start Date</th>
         <th>Due Date</th>
         <th>Is compeleted</th>
     </tr> 
     <tr>
         <td>{{ task.name }} </td>
         <td>{{ task.assignee }}</td>
         <td>{{ task.start_date }}</td>
         <td>{{ task.due_date }}</td>
         <td>{{ task.is_completed }}</d>
    </tr> 
</table>

но он показывает только заголовки таблицы, а не ее содержимое

вот моя модель задачи

from django.db import models
from django.conf import settings
from django.urls import reverse


# Create your models here.
class Task(models.Model):
    name = models.CharField(max_length=200)
    start_date = models.DateTimeField()
    due_date = models.DateTimeField()
    is_completed = models.BooleanField(default=False)
    project = models.ForeignKey(
        "projects.Project",
        related_name="tasks",
        on_delete=models.CASCADE,
    )
    assignee = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        null=True,
        related_name="tasks",
        on_delete=models.SET_NULL,
    )

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse("show_my_tasks")

На ответ на ваш предыдущий вопрос было что-то вроде:

{% for project in projects_list %}
     ...

     {% if project.tasks.count > 0 %}
          # Displaying the table in here with the project's task info...
     {% else %}
          <p> no tasks for this project </p>
     {% endif %}

     ...
{% endfor %}

Вы должны перебрать все задачи проекта set внутри таблицы. Например:

# Within the true portion of the if statement...
{% if project.tasks.count > 0 %}
     # Displaying the table in here with the project's task info...

     <table>
          <thead>
               <tr>
                    <th>Name</th>
                    <th>Assignee</th>
                    <th>Start Date</th>
                    <th>Due Date</th>
                    <th>Is compeleted</th>
               </tr> 
          </thead>
  
          <tbody>
               # The set of related tasks for the current project -> project.tasks.all
               {% for task in project.tasks.all %}
                    <tr>
                         <td>{{ task.name }} </td>
                         <td>{{ task.assignee }}</td>
                         <td>{{ task.start_date }}</td>
                         <td>{{ task.due_date }}</td>
                         <td>{{ task.is_completed }}</d>
                    </tr> 
              {% endfor %}
         </tbody>
    </table>
{% else %}
     <p> no tasks for this project </p>
{% endif %}
Вернуться на верх