1

I've got a function which returns an array consisting of a object and four strings like this: [obj1, 'date1', 'time1', 'title1', 'description1']

I give this to my template where I want to display some variables from the obj (for example obj1.name and obj1.surname) as well as the strings.

Right now i'm using

{% for obj in entries %}
 {{obj}} </br>
{% endfor %}

This displays the value of

def __str__(self):
    return self.name

of the obj and the all of the strings but i cant figure out how to access the object variables as well as choose the strings i want to display in one loop.

I've also tried using obj.name and obj.surname which works fine, my problem is selecting the string variables i want to display. Should i give them a class to access them? The goal is not to save them in the database so i dont really want to use a model etc.

Thanks for your help!

ItsMeTheBee
  • 353
  • 2
  • 20

1 Answers1

0

You can try make your own templatetag as it is described here. And then try something like this:

{% if obj|get_class == 'your_object_class' %}
    <p>{{ obj.attribute_AA }}</p> 
    <p>{{ obj.attribute_BB }}</p>
{% else %}
    {{ obj }}
{% endif %}
Chiefir
  • 2,561
  • 1
  • 27
  • 46