I have a running total template tag which looks like
from django.template import Library
register = Library()
@register.filter
def running_total(list, var_name):
return sum(getattr(obj, var_name) or 0 for obj in list)
It works when I need a running total in normal querysets, but when I use a annotated queryset I get the exception 'dict' object has no attribute 'total'.
When I print a normal queryset in my template I get [<Item: Item #1>], but when I print a annotated queryset I get a list with a tuple [{'total_amount': Decimal('0.00'), ...].
Should I somehow convert the list in my templatetag?
I've tried adding
list = list(list)
but it still doesn't work.
list. you are overriding the default type.