title: Accessing items in a list through template tags in Django template tags
body: <p><a href="https://i.stack.imgur.com/wbE93.png" rel="nofollow noreferrer">Template tag screenshot and possible solution options</a></p>
  <p>First time, posting to stack-overflow. Please excuse if formatting is not ideal.</p>
  <p><strong>html</strong></p>
  <pre><code>&lt;tbody&gt;
         {% for list in todolist %} 
            &lt;tr&gt;
              &lt;td&gt;
                 &lt;a href=&quot;{% url 'todo_detail' list.pk %}&quot;&gt;{{ list.name }}&lt;/a&gt;  
                    &lt;/td&gt;
                     &lt;td&gt;
                     {{ list.items.all|length }}
                      &lt;/td&gt;
                      &lt;td&gt;
      {% comment %}need this to be allCompleted[list.id - 1]
   #allCompleted.0 works. allCompleted[0] or allCompleted['0'] does not.{% endcomment %}
  
                         {% if allCompleted == True %}  
  
                         {{ allCompleted|getindex:list.id }}
  
                          Yes
  
                          {% else %}
  
                          No  
  
                          {% endif %}
                      &lt;/td&gt;
                  &lt;/tr&gt; 
                 {% endfor %} 
              &lt;/tbody&gt;
  </code></pre>
  <p><strong>Views.py:</strong></p>
  <pre><code>class TodoListListView(ListView):
  model = TodoList
  context_object_name = &quot;todolist&quot;
  template_name = &quot;todos/list.html&quot;
  
  def get_context_data(self, **kwargs): 
      context = super().get_context_data(**kwargs) 
      allCompletedList = [] 
      for list in TodoList.objects.all(): 
          
          allCompleted = True
          for item in list.items.all(): 
              if item.is_completed == False: 
                  allCompleted = False 
          allCompletedList.append(allCompleted)
          
          context['allCompleted'] = allCompletedList
  
      print ('context: ', context)
      return context 
  </code></pre>
  <p><strong>Models.py</strong></p>
  <pre><code>class TodoList(models.Model):
      name = models.CharField(max_length=100, blank=False)
      created_on = models.DateTimeField(auto_now_add=True)
  
      def __str__(self): 
          return self.name 
  
  class TodoItem(models.Model):
      task = models.CharField(max_length=100)
      due_date = models.DateTimeField(null=True, blank=True)
      is_completed = models.BooleanField(default=False)
      list = models.ForeignKey(&quot;Todolist&quot;, related_name=&quot;items&quot;, on_delete=models.CASCADE)
  
      def __str__(self): 
          return self.task 
  </code></pre>
  <p><strong>When printing context:</strong>
  I get 'allCompleted': [False, True]
  This is accurate as I have some items in housing chores not completed but I triple checked to make sure all my coding projects are completed.</p>
  <p>As seen from the HTML screenshot, I need something like:</p>
  <pre><code>{{ allCompleted[list.id - 1] }} to match with the corresponding list in each row.
  </code></pre>
  <p>But it seems Django does not like that. I've tried many combos like allCompleted['list.id-1']. Strangely, allCompleted.0 = False but allCompleted[0] gets a parse error. I have also tried to create a custom template tag in my app/templatetag folder under a file I made (getindex.py)</p>
  <pre><code>from django import template
  from todos.models import TodoItem, TodoList
  
  register = template.Library()
  
  def getindex(lst, idx):
     return lst[idx]
  
  register.filter(getindex)
  </code></pre>
  <p>For my template tag, I did <code>{{ allCompleted|getindex:list.id-1 }}</code> and it says getindex is not a valid filter so maybe I am registering it incorrectly?</p>
  <p>If there is no way to access <code>allCompleted[list.id - 1]</code>, I thought of other solutions explained in my HTMl screenshot.</p>