0

Assume I've created a search views with chain (multiple search from different app).

I want to display my result at the same place:

    {% for object in object_list %}
    {% with object|class_name as klass %}
    {% if klass == 'Post' %}
           
      {{ object.title }}

    
    {% elif klass == 'Catego' %}
           
      {{ object.name }}
      
    
    {% elif klass == 'UserProfile' %}
           
      {{ object.user.username }}
      
           
    {% else %}
           
    {% endif %}
        
    {% endwith %}
    
{% empty %}

{% endfor %}

Everything is ok. I got all of my result. Now, if I want to separate this result in different div (row and collapse class).

If I try this:

<div class="row collapse" id="collapseNutri">
    {% for object in object_list %}
            {% with object|class_name as klass %}
            {% if klass == 'Post' %}
                   
              {{ object.title }}
              
            {% endif %}
            {% endwith %}
            {% endfor %}
</div>   
<div class="row collapse" id="collapseCatego">         
            {% for object in object_list %}
            {% with object|class_name as klass %}
            {% if klass == 'Catego' %}
                   
              {{ object.name }}
              
            {% endif %}
            {% endwith %}
            {% endfor %}
</div>
<div class="row collapse" id="collapseUserProfile">             
            {% for object in object_list %}
            {% with object|class_name as klass %}
            {% if klass == 'UserProfile' %}
                   
              {{ object.user.username }}
              
                   
            {% else %}
            {% endif %}
            {% endwith %}
            {% empty %}
            {% endfor %}
</div>

I only got the Post result... I'm beginning with Django. Does anyone has an idea to separate search result in order to add different html presentation?

Thierry Lathuille
  • 21,301
  • 10
  • 35
  • 37
Louis
  • 358
  • 2
  • 10

0 Answers0