django template to populate bootstrap rows and columns

后端 未结 5 594
温柔的废话
温柔的废话 2020-12-05 01:14

So here\'s my problem: I\'ve got a bunch of instances of a class. I would like to have a sort of table of these instance objects, so that there is a maximum of six in every

5条回答
  •  萌比男神i
    2020-12-05 01:57

    You could make the code a bit more generic. Here's the logic:

    queryset = Class.objects.all()
    set_length = queryset.count()
    
    
    {% for i in queryset %}

    i.attr

    i.attr

    {% if forloop.counter|divisibleby:"6" or forloop.last %}
    {% endif %} {% endfor %}

    I hope this solves your problem :-)

提交回复
热议问题