[Answered ]-I have a list of objects and would like to return an attribute with another attribute

2👍

Try this –

{% for content in content_list %}
    {% if content.title == 'two' %}
        {{ content.content }}
    {% else %}
        {{ content.content }}
    {% endif %}
{% endfor %}

Note: Only if list is small

0👍

If you want to split your content in columns, just create a list for each kind of object and iterate over them.

In your view, do something like this:

l1 = [(title: 'one', content: 'foo'),] # All the objects with title 'one'
l2 = [(title: 'two', content: 'bar'),] # All the objects with title 'two'
context = {'content_list1': l1, 'content_list2': l2}

And in your html iterate over each list:

{% for content in content_list1 %}
{{ content.content }}
{% endfor %}

{% for content in content_list2 %}
{{ content.content }}
{% endfor %}

I hope it’s that what you are looking for.

Leave a comment