RE: Need help for nested list in template

2009-05-19 Thread Will Matos

In this case a dictionary would not be necessary if he is indeed adding
the model object itself:

>  user_status_list = UserStatus.objects.filter(id =20,time__gte
> = somelist[val], time__lte = somelist[val+1))
>   for item in user_status_list:
>testing_list.append(item)
>

It appears he is appending the UserStatus instance. 

W
-Original Message-
From: django-users@googlegroups.com
[mailto:django-us...@googlegroups.com] On Behalf Of Tom Evans
Sent: Tuesday, May 19, 2009 10:33 AM
To: django-users@googlegroups.com
Subject: Re: Need help for nested list in template


On Tue, 2009-05-19 at 06:46 -0700, laspal wrote:
> Hi,
> My model is :
>id  val msg
>20 1234 text
>20 1245text
>20 1275  text
>20 1356  text
> 
> so I have to display record in calendar format.
> I am doing it in this way:
> final_list =[]
> somelist = [1200, 1250, 1300, 1350, 1400]
> val = 0
> i = iter(range(5))
> testing_list =[]
> for item in i:
> user_status_list = UserStatus.objects.filter(id =20,time__gte
> = somelist[val], time__lte = somelist[val+1))
>   for item in user_status_list:
>testing_list.append(item)
> 
> final_list.append(testing_list)
> 
> so my final list should look like:
> 
> [ [  [20, 1234, sdfs], [20, 1245, sdffd]  ],  [ 20,1275, dfdfgf], [ ],
> [20, 1356, dsfdf] ]
> 
> wanted to know How can I use this list in my template.
> for item in final_list:
>  for val in item:
> print val.id, val.val, val.msg
> 
> which is wrong.
> how can I fix this.
> 
> thanks...
> 

Build a dict instead, where you wish to refer to specific elements.

Eg:

foo = [ { 'id': 20, 'name': sdfs, }, { . } ]

and 

{% for item in foo %}
{{ item.name }}
{% endfor %}

Cheers

Tom




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



Re: Need help for nested list in template

2009-05-19 Thread Tom Evans

On Tue, 2009-05-19 at 06:46 -0700, laspal wrote:
> Hi,
> My model is :
>id  val msg
>20 1234 text
>20 1245text
>20 1275  text
>20 1356  text
> 
> so I have to display record in calendar format.
> I am doing it in this way:
> final_list =[]
> somelist = [1200, 1250, 1300, 1350, 1400]
> val = 0
> i = iter(range(5))
> testing_list =[]
> for item in i:
> user_status_list = UserStatus.objects.filter(id =20,time__gte
> = somelist[val], time__lte = somelist[val+1))
>   for item in user_status_list:
>testing_list.append(item)
> 
> final_list.append(testing_list)
> 
> so my final list should look like:
> 
> [ [  [20, 1234, sdfs], [20, 1245, sdffd]  ],  [ 20,1275, dfdfgf], [ ],
> [20, 1356, dsfdf] ]
> 
> wanted to know How can I use this list in my template.
> for item in final_list:
>  for val in item:
> print val.id, val.val, val.msg
> 
> which is wrong.
> how can I fix this.
> 
> thanks...
> 

Build a dict instead, where you wish to refer to specific elements.

Eg:

foo = [ { 'id': 20, 'name': sdfs, }, { . } ]

and 

{% for item in foo %}
{{ item.name }}
{% endfor %}

Cheers

Tom


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



RE: Need help for nested list in template

2009-05-19 Thread Will Matos


{%for item in final_list%}
 {%for val in item%}
{{val.id}}, {{val.val}}, {{val.msg}}
{%endfor%}
{%endfor%}



-Original Message-
From: django-users@googlegroups.com
[mailto:django-us...@googlegroups.com] On Behalf Of laspal
Sent: Tuesday, May 19, 2009 9:47 AM
To: Django users
Subject: Need help for nested list in template


Hi,
My model is :
   id  val msg
   20 1234 text
   20 1245text
   20 1275  text
   20 1356  text

so I have to display record in calendar format.
I am doing it in this way:
final_list =[]
somelist = [1200, 1250, 1300, 1350, 1400]
val = 0
i = iter(range(5))
testing_list =[]
for item in i:
user_status_list = UserStatus.objects.filter(id =20,time__gte
= somelist[val], time__lte = somelist[val+1))
  for item in user_status_list:
   testing_list.append(item)

final_list.append(testing_list)

so my final list should look like:

[ [  [20, 1234, sdfs], [20, 1245, sdffd]  ],  [ 20,1275, dfdfgf], [ ],
[20, 1356, dsfdf] ]

wanted to know How can I use this list in my template.
for item in final_list:
 for val in item:
print val.id, val.val, val.msg

which is wrong.
how can I fix this.

thanks...




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



Need help for nested list in template

2009-05-19 Thread laspal

Hi,
My model is :
   id  val msg
   20 1234 text
   20 1245text
   20 1275  text
   20 1356  text

so I have to display record in calendar format.
I am doing it in this way:
final_list =[]
somelist = [1200, 1250, 1300, 1350, 1400]
val = 0
i = iter(range(5))
testing_list =[]
for item in i:
user_status_list = UserStatus.objects.filter(id =20,time__gte
= somelist[val], time__lte = somelist[val+1))
  for item in user_status_list:
   testing_list.append(item)

final_list.append(testing_list)

so my final list should look like:

[ [  [20, 1234, sdfs], [20, 1245, sdffd]  ],  [ 20,1275, dfdfgf], [ ],
[20, 1356, dsfdf] ]

wanted to know How can I use this list in my template.
for item in final_list:
 for val in item:
print val.id, val.val, val.msg

which is wrong.
how can I fix this.

thanks...


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---