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 = No
On Friday, August 23, 2013 5:58:38 PM UTC+2, Daviddd wrote:
>
> Dear All,
>
> In my view I create the following dictionary of lists from a queryset
>
> #view.py
> queryset = MyModel.objects.filter(owner=user,
> dashboard=tab).order_by('position')
> my_dict = collections.defaultdict(lambda: colle
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 a
Thanks Tom for replying!
The code used to create the dict is:
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)
Basically I have one field in the queryset calle
On 23 Aug 2013, at 16:58, Daviddd wrote:
> In my template I tried:
>
> {% for key, groups in queryset.iteritems %}
> groups = {{ groups }}
> {% for group_key, cols in groups.iteritems %}
> cols = {{ group_key }}
> {% for objs in cols %}
> {# rest of the code #}
>
Dear All,
In my view I create the following dictionary of lists from a queryset
#view.py
queryset = MyModel.objects.filter(owner=user,
dashboard=tab).order_by('position')
my_dict = collections.defaultdict(lambda: collections.defaultdict(list))for
obj in queryset:
my_dict[int(obj.positi
6 matches
Mail list logo