title: django template to populate bootstrap rows and columns
body: <p>So here's my problem: I've got a bunch of instances of a class. I would like to have a sort of table of these instance objects, so that there is a maximum of six in every row. In bootstrap terms, I would like each object to be represented by a thumbnail in a "div" of class "span2".  </p>
  
  <p>My initial impulse was to use a nested for loop, but I am having trouble manipulating my index variable in the template, and I can't figure out how to do so outside of my template.  </p>
  
  <p>Here is generally what the python/django template/pseudo code is I'm trying to figure out. </p>
  
  <pre><code>queryset = Class.objects.all()
  set_length = queryset.count()
  
  num_rows = set_length/6 
  #because I want 6 columns in each row, each with one instance
  
  set_as_list = list(queryset) 
  # have a list so I can iterate through objects by index
  
  for i in range(table_rows):
      # make a row
      &lt;div class="row"&gt;
      for j in range (i*6,(i+1)*6):
          #make six or less columns
          &lt;div class="span2"&gt;
             &lt;p&gt;set_as_list[j].attribute1&lt;/p&gt;
             &lt;p&gt;set_as_list[j].attribute2&lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt; # end row
  </code></pre>
  
  <p>I hope this flagrant mixing of django templating language, python, and html doesn't offend anybody too badly. just trying to express the idea of what I'm trying to do. I would appreciate any help someone may be willing to offer because I've been struggling with this for days and have done quite a bit of searching for a solution both within a template and outside. </p>
  
  <p>I also realise that there will be need to be a final row with the remainder of objects after the integer division.  </p>