On Wednesday, 11 January 2012 21:33:48 UTC, somecallitblues wrote:
>
> Hi Djangoers,
>
> I have a default dict variable final_d = defaultdict(list) that looks like 
> this:
>
> [(order1, [customer2, customer1]), (order2, [customer3, customer5, 
> customer6]) ]
>
> I've tried everything possible inside the template and I can't unpack this 
> thing. I'm passing final_d to the template inside the dictionary like 
> this: d = {'final_d':final_d}
>
> This is my template which should I think work from what I've read on SO 
> and elsewhere:
>
> <ul class="main-listing">
>                                     {% for order, customers in final_d %}
>
>                                         <li>
>                                             <h3><a href="{{ 
> order.getabsoluteurl }}">{{ ordder.name }}</a></h3>
>                                             <h4>Cusotmers</h4>
>                                             <ul class="customers">
>                                             {% for customer in customers %}
>                                                 <li><a href="#">{{ 
> customer.name }}</a></li>
>                                             {% endfor %}
>                                             </ul>
>                                         </li>
>                                     {% endfor %}
> </ul>
>
> I have tried absolutely everything and I can't get this to render.
>
> The above code doesn't render a result. if I change {% for order, 
> customers in final_d %} to {% for order in final_d %} I do get the order 
> details, but I can't access customer details.
>
> Thank you for your help!
>
> -m
>

A defaultdict operates just like a normal dict in that iterating over it 
just returns the keys. Usually you would do {% for order, customers in 
final_d.items %} to iterate over both keys and values.

However I'm confused by your initial description. What you show is not a 
dict at all, but a list of 2-tuples (each containing a string and a list). 
Is that a single value of the dict, or what?
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/WIowdkQrZGoJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to