0

Basically, I want to use a Bootstrap Carousel with a queryset. My question is as to how I should iterate over the queryset so that I can put three objects into a div and then the next three into another div and so on depending on the size of the queryset. See the preudocode below.

{% for group in object_list/3 %}
 <div class="">
  {% for object in group %}
   <p>{{object}}</p>
  {% endfor %}
 </div>
{% endfor %}
zara30
  • 31
  • 2

1 Answers1

0

You could add a filter called chunks like in this stackoverflow answer:

@register.filter
def chunks(iterable, size):
    iterator = iter(iterable)
    for first in iterator:
        yield chain([first], islice(iterator, size - 1))

and then use the filter in django templates

Paul
  • 324
  • 1
  • 7