Group by field

Hello. I have two models:

class Project(models.Model):
    code = models.CharField(max_length=255)
    name = models.CharField(max_length=255)

class Task(models.Model):
    project = models.ForeignKey(Project, on_delete=models.CASCADE)
    name = models.CharField(max_length=1000)
    description = models.CharField(max_length=5000, blank=True, null=True)

I need to get on my page table
image
What is the best method to modify my Task.objects.all()?
Please help the Django beginner! Thank you!

Create your query for the Task models to sort by project. Then, when you’re iterating over that queryset, compare the current project to the project from the previous row. Add your new header into the table when the project changes.

Thank you. It was my first idea. Done!