I solved in this way:

    my_dict = collections.defaultdict(lambda: collections.defaultdict(list))

    for obj in queryset:
        
my_dict[int(obj.position.split('-')[0])][int(obj.position.split('-')[2])].append(obj)

    for obj in my_dict:            
        my_dict[obj].default_factory = None

    return Response({'queryset': dict(my_dict)}, 
template_name='_internal_template.html')


{% for groups in queryset.itervalues  %}

    groups = {{ groups }}    
    <br><br>

    {% for cols in groups.itervalues  %}

      cols = {{ cols }}    
      <br><br>

      {% for obj in cols  %}

        obj = {{ obj}} in <br><br>
        obj info = {{ obj.title }}, {{ obj.abstract }}<br>

      {% endfor %}      

    {% endfor %}
{% endfor %}


Linked question using default_factory: 
http://stackoverflow.com/questions/4764110/django-template-cant-loop-defaultdict

Thanks!

On Monday, August 26, 2013 12:46:30 PM UTC+2, tom wrote:
>
> On Monday, 26 August 2013, Daviddd wrote:
>
>> Sincerely, I don't know how I can create the dict without using 
>> defaultdict.
>>
>> D
>>
>
> You can create it using a defaultdict if you want to, but once it is 
> created, and before you pass it to the template, loop through all the 
> values of your outer dict and coerce them to dicts using dict(). You are 
> already doing this for your outer defaultdict, which is why the first loop 
> works in your template.
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to