[Django]-Django-tables2 column total

3👍

Your screenshot shows that django-tables2 correctly assumes there is a footer on your table (yay!) but it seems that nothing is returned from the lambda. You can try to replace it by something like this to see what’s going on:

def suma_footer(table):
    try:
        s = sum(x['suma'] for x in table.data)
        print 'total:', s
    except Exception e:
        print str(e)
        raise

    return s


class MokejimaiTable(tables.Table):
    suma = tables.Column(footer=suma_footer)

    class Meta:
        model = Mokejimai
        attrs = {"class": "paleblue"}
        fields = ('id', 'imone', 'sask', 'nr', 'suma', 'skola_pagal_agnum', 'data', 'date_entered')

If something goes wrong while computing the sum, you should see a exception printed, if a value is computed, you should see ‘total: ‘ printed.

👤Jieter

Leave a comment