# creating one table from two lists in django template

**URL:** <https://forum.djangoproject.com/t/creating-one-table-from-two-lists-in-django-template/5372>\
**Category:** Using Django\
**Created:** [November 23, 2020, 2:05am UTC](https://forum.djangoproject.com/t/creating-one-table-from-two-lists-in-django-template/5372 "2020-11-23T02:05:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bwindon](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/bwindon/32/2552_2.png) [@bwindon](https://forum.djangoproject.com/u/bwindon)\
**Post date:** [November 23, 2020, 2:05am UTC](https://forum.djangoproject.com/t/creating-one-table-from-two-lists-in-django-template/5372/1 "2020-11-23T02:05:32Z")

</div>

Hi,

I have a view that queries all data in my model (DrinkModel) and passes values to a table. I want to add a column to the table from a function that creates a list. If I pass the second list to the template i need a second iteration and effective just produce a column below the table.

My view:  
def d\_list(request):  
drinks = models.DrinkModel.objects.all()  
print(drinks)  
duration\_qs = duration\_queryset()  
return render(request, ‘list.html’, {‘drinks’: drinks, ‘duration\_qs’: duration\_qs})

My template:  
  
{% for drink in drinks %}

```
    <tr>
        <td>{{ drink.pk }}</td>
        <td><a href="{% url 'detail' drink.id %}"/> {{ drink.dn }}</td>
        <td>{{ drink.ds }}</td>
        <td>{{ drink.df }}</td>
        <td>{{ drink.dt }}</td>

    </tr>
{% endfor %}

{% for qs in duration_qs %}
    <tr>
        <td>{{ qs }}</td>
    </tr>
{% endfor %}

```

Is there a way to iterate over duration\_qs so that it lines up as the far right column of the first table?

Many thanks,  
Brad

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 23, 2020, 3:05am UTC](https://forum.djangoproject.com/t/creating-one-table-from-two-lists-in-django-template/5372/2 "2020-11-23T03:05:19Z")

</div>

Since you didn’t include your definition of duration\_queryset it’s difficult to know how to integrate the two.

You’ve got a couple of different ways to handle this.

One way would be to [annotate](https://docs.djangoproject.com/en/3.1/ref/models/querysets/#annotate) your drinks queryset with the values coming from your duration queryset. That would be my first choice - have the database join the values in the query to give you a single combined list.

You could use the [Python map function](https://docs.python.org/3/library/functions.html#map) to create a combined iterable to be passed to the render function.

You could iterate over your drinks list and use the index to refer to the corresponding entry in the duration\_qs. See the reference to `counter` in the template [for loop](https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#for) docs
