'Django template regorup

I want to regroup this on the basis of ingredients. this is my sample result which I want Just like the below picture as there is more than one certificate so I am showing them in one row.

enter image description here

Ingredient_name, all the stop_name associated with that ingredient, all the stop_longitude associated with that ingredient and so on in one table row.

Right now its showing like this and you can see that the ingredient name is repeating . enter image description here

model

class SupplyChainStops(models.Model):
    ingredient = models.ForeignKey(Ingredients, null=True, on_delete=models.CASCADE)

    stop_name = models.CharField(max_length=1024, null=True, blank=True)
    stop_longitude = models.CharField(max_length=500, null=True, blank=True)
    stop_latitude = models.CharField(max_length=500, null=True, blank=True)
    is_supplier = models.BooleanField(default=False, blank=True, null=True)

    def __str__(self):
        return f'{self.stop_name}'

query

items = SupplyChainStops.objects.all()

template

        {% for item in items %}
            <tr class="text-black">
                <td>{{ item.ingredient }}</td>
                <td>{{ item.stop_name }}
                <td>{{ item.stop_longitude }}
                <td>{{ item.stop_latitude }}

This is my DB structure

enter image description here

This is my desired output enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source