Split Django Queryset in a template for Bootstrap Carousel

I have a model Bannerwith imageand fields name. I need data from this model that will be displayed in groups of three on a moving Bootstrap cassette.

My current implementation is the most expensive and easiest I could think of.

banner1 = Banners.objects.filter(id__exact=1) repeated for 9 entries in the model.

My question is, can I split one query Banners.objects.all()into three groups of three records, and then how can I display three groups on three different slides of the Bootstrap carousel?

0
source share
1 answer

django divisibleby. , ( , ):

{% for banner in banners %}
{% if forloop.counter0|divisibleby:"3" %}
<!-- your carousel wrapping code here -->
{% endif %}
<!-- code for each individual banners here -->
{% if forloop.counter0|divisibleby:"3" %}
<!-- rest of your carousel wrapping code here -->
{% endif %}

, Banners.objects.all()

0

All Articles