I have a dictionary of dictionaries that I need to open up in a template.

The dictionary:
'values': {(1L, 2L): {'selling_costs__sum': None, 'sale_price__sum': None,
'debt__sum': None, 'estimate__quote__sum': None},
(3L, 2L): {'selling_costs__sum': Decimal('10.45'), 'sale_price__sum':
Decimal('50.00'), 'debt__sum': Decimal('0.00'), 'estimate__quote__sum':
Decimal('100.00')}}

My templatetag:
from django import template
register = template.Library()

@register.filter
def lookup(container, key):
    if type(container) is dict:
        return container.get(key)
    elif type(container) in (list, tuple):
        return container[key] if len(container) > key else None
    return None

And my template code:
{% for location in locations %}
    {% for category in categories %}
<tr>
    <td>{{ location }}</td>
    <td>{{ category }}</td>
    <td>${{ values|lookup:(location.id, category.id)|lookup:'
selling_costs__sum' }}</td>
</tr>
    {% endfor %}
{% endfor %}

The error I get is: lookup requires 1 arguments, 0 provided.

The location.id and category.id both generate the correct values. It seems
that template tags can't take a tuple as a key for a dictionary.

Also I read that one cannot chain a filter like this. Is this true?

Any suggestions on how to read data from the dictionary values?

Thanks!

Mark

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEqej2M%2BZHES%2BfiSwuDiMJPL52OEKGKmtz7fu2mOf5YD3NtUgA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to