django - Prevent cycle counting the first two iteration -


im trying display first 2 objects of forloop in special way. , rest should grouped in three.

like this:

<div class="row">     object 1      object 2 - object slug </div><!--/end first row 2 objects-->   <div class="row">     object 3      object 4      object 5 </div><!--/end row 3 objects-->  <div class="row">     object 6      object 7      object 8 </div><!--/end row 3 objects--> 

here template code:

{% object in object_list %}      {% if forloop.first %}         <div class="row">              {{object.name}}      {% elif forloop.counter == 2 %}              {{object.name}} - {{object.slug}}          </div><!--/end first row 2 objects-->      {% else %}      {% cycle '<div class="row">' '' '' %}              {{object.name}} - {{object.slug}}       {% cycle '' '' '</div><!--/end row 3 objects-->' %}       {% endif %}  {% endfor %} 

this code not work, because cycle tag counts first , second. how fix this?

in opinion shouldn't in template. should create such object in view , iterate.

for example, have object array:

object = ['object1', 'object2', 'object3', 'object4' , 'object5', 'object6', '...'] 

and idea make object this:

object = (['object1', 'object2'], ['object3', 'object4' , 'object5'], [...]) 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -