title: How to use for in another for cycle in django
body: <p>I'm building some kind of list in which we have Section and Category assigned to the section.</p>
  
  <p>In my view.py it looks like this:</p>
  
  <pre><code>args['sections'] = ShopSection.objects.all().order_by('name')
  args['categories'] =  ShopCategory.objects.all().order_by('-name')
  </code></pre>
  
  <p>And my template looks like this:</p>
  
  <pre><code>&lt;div class="panel side-panel-1"&gt;
  &lt;h4 class="title1"&gt;Разделы&lt;/h4&gt;
  &lt;ul class="clear-list"&gt;
  &lt;li class=""&gt;
          &lt;a href="/advert/adverts.aspx"&gt;Все разделы&lt;/a&gt;
  &lt;/li&gt;
  {% for section in sections %}
      &lt;li class=""&gt;
          &lt;!--&lt;a href="/advert/adverts.aspx&amp;sec{{ section.id }}"&gt;{{ section.name }}&lt;/a&gt;--&gt;
          &lt;a class="" data-dropdown="autoCloseExample" aria-controls="autoCloseExample" aria-expanded="false"&gt;
              {{ section.name }} ({{ section.shopcategory_set.count }}) {{section.shopcategory_set.id}} {{ section.id }}
          &lt;/a&gt;
          &lt;ul id="autoCloseExample" class="f-dropdown" data-dropdown-content tabindex="-1" aria-hidden="true" aria-autoclose="false" tabindex="-1"&gt;
  
              {% for category in categories %}
              {% if section.id == category.section_id%}
              &lt;li style="width: 100%;"&gt;&lt;a href="#"&gt;{{ category.name }} sec={{section.id}} cat={{category.id}} catsec={{category.section_id}}&lt;/a&gt;&lt;/li&gt;
              {% else %}
              {% endif %}
              {% endfor %}
          &lt;/ul&gt;
  {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p></p>
  
  <p>The working page is <a href="http://open.tm:8080/store/store.aspx" rel="nofollow">here</a>.</p>
  
  <p>The problem is when I use <code>{% if section.id == category.section_id %}</code> I want to filter category list according to the section id, but <code>section.id</code> is not defining properly.</p>
  
  <p>For example: </p>
  
  <ul>
  <li>If I use <code>{% if section.id &gt; 3 %}</code> then in cycle it defines <code>section.id</code> as <code>4</code> </li>
  <li>If i use <code>{% if section.id &lt; 3 %}</code> then in cycle it defines <code>section.id</code> as <code>2</code></li>
  </ul>
  
  <p>what i want is</p>
  
  <ul>
  <li>-Section id-1</li>
  <li>--Category1 which has section_id-1</li>
  <li>--Category2 which has section_id-1</li>
  <li>--Category3 which has section_id-1</li>
  <li>-Section id-2</li>
  <li>--Category4 which has section_id-2</li>
  <li>--Category5 which has section_id-2</li>
  <li>--Category6 which has section_id-2</li>
  </ul>