I needed to display formset into table and I didn´t like solution I have found. So I have written this simple tag you can use it in templates like this:
{% for row in formset|square_it:6 %}
    <tr>
        <td>
        </td>
    {% for form in row %}
        <td>        
        {% for field in form %}
            {{ field }}
        {% endfor %}
        </td>
    {% endfor %}
1 2 3 4 5 6 7 8 9 10  | @register.filter
def square_it(l, n):
    """
    This filter squares|groups list into smaller lists of given number of elements
    >>>print square_it(range(74), 4)
    [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31], [32, 33, 34, 35], [36, 37, 38, 39], [40, 41, 42, 43], [44, 45, 46, 47], [48, 49, 50, 51], [52, 53, 54, 55], [56, 57, 58, 59], [60, 61, 62, 63], [64, 65, 66, 67], [68, 69, 70, 71], [72, 73]]
    
    """
      
    return [l[i:i+n] for i in range(0, len(l), n)]
 | 
More like this
- Add Toggle Switch Widget to Django Forms by OgliariNatan 1 month, 4 weeks ago
 - get_object_or_none by azwdevops 5 months, 2 weeks ago
 - Mask sensitive data from logger by agusmakmun 7 months, 2 weeks ago
 - Template tag - list punctuation for a list of items by shapiromatron 1 year, 9 months ago
 - JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 1 year, 9 months ago
 
Comments
Please login first before commenting.