A: 

I think you can use forloop.parentloop.counter inside of the inner loop to achieve the numbering you're after.

Jeb
Good thought, but that counter only increments when the outer loop iterates. The first section's articles are all labeled 1, the second section's are all 2, etc.
Patrick McElhaney
Ah, of course. I think you'd have to make a custom template tag for that.
Jeb
A: 

You could just use an ordered list instead of unordered:

{% regroup articles by section as articles_by_section %}

<ol>
{% for article in articles_by_section %}        
    <h4>{{ article.grouper }}</h4>
    {% for item in article.list %}  
        <li>{{ item.headline }}</li>
    {% endfor %}
{% endfor %}
</ol>
Daniel
Good point, but I don't think that's valid HTML.
Patrick McElhaney
+2  A: 

Following Jeb's suggeston in a comment, I created a custom template tag.

I replaced {{ forloop.counter }} with {% counter %}, a tag that simply prints how many times it's been called.

Here's the code for my counter tag.

class CounterNode(template.Node):

  def __init__(self):
    self.count = 0

  def render(self, context):
    self.count += 1
    return self.count

@register.tag
def counter(parser, token):
  return CounterNode()
Patrick McElhaney
That's neat. One small improvement might be to pass an optional parameter to the tag so you can have multiple counters on the page (self.count would be a dictionary.)
Tom
Thanks. Actually, I do have multiple counters on the same page and it "just works." Each instance of "{% counter %}" corresponds to a different instance of CounterNode. So each {% counter %} individually tracks how many times it's been called.
Patrick McElhaney
+1  A: 

This isn't exactly neat, but may be appropriate for someone:

{% for article in articles %}        
   {% ifchanged article.section %}
      {% if not forloop.first %}</ul>{% endif %}
      <h4>{{article.section}}</h4>
      <ul>
   {% endifchanged %}
          <li>{{forloop.counter}}. {{ article.headline }}</li>
   {% if forloop.last %}</ul>{% endif %}
{% endfor %}
Tom