Modify Django for loop every four iterations

Viewed 646

I have a calendar generated by Django and styled with Bootstrap. Here is the code in the Django template :

<div class="content">
  {% for month in period.get_months %}
    <div class="col-md-3">
      <div class="row row-centered">
        <button class="btn btn-custom active" href="{% url "month_calendar" calendar.slug %}{% querystring_for_date month.start 2 %}">{{month.name}}</button>
      </div>
      <div>
        {% month_table calendar month "small" %}
      </div>
    </div>
  {% endfor %}
</div>

Now, since months have a different number of weeks they have different heights I would like to avoid something like this: enter image description here

I understand from this answer that the best solution would be to use a clearfix.

So, how can I modify the for loop in my template so that Django inserts an extra line <div class="clearfix"></div> every four items?

1 Answers
Related