Re: Accessing objects from a dictionary in templates

2012-03-24 Thread gowtham
Hi Samuel, Thanks a ton for this detailed suggestion. I was almost certain, the solution i was trying is not the optimal. Now its very clear. Thanks very very much. You made my weekend. I will be all busy backing up my database and implementing what you suggested. Initially after reading your

Re: Accessing objects from a dictionary in templates

2012-03-24 Thread Sam Lai
On 24 March 2012 09:29, gowtham wrote: > Template tag filters like this (made one for each field in the library > object) helps me to get what i wanted But, that seems too silly to do... > > in template > {{ reslibdic|hash2libcode:res.result_id }} > I had the same

Re: Accessing objects from a dictionary in templates

2012-03-23 Thread gowtham
Template tag filters like this (made one for each field in the library object) helps me to get what i wanted But, that seems too silly to do... in template {{ reslibdic|hash2libcode:res.result_id }} in template tag file: def hash2libcode(h,key): if key in h: return

Re: Accessing objects from a dictionary in templates

2012-03-23 Thread gowtham
sorry, I meant to say "It's quite possible i am NOT doing the right thing." On Fri, Mar 23, 2012 at 3:24 PM, gowtham wrote: > Yes, That is correct. > > Let me step back a bit and explain you what i am trying. It's quite > possible i am doing the right thing. >

Re: Accessing objects from a dictionary in templates

2012-03-23 Thread gowtham
Yes, That is correct. Let me step back a bit and explain you what i am trying. It's quite possible i am doing the right thing. I have two models (Library and Result) linked by a third linking model (libraryresult (has id, library_id and result_id fields FKeyed to respective tables). A many to

Re: Accessing objects from a dictionary in templates

2012-03-23 Thread Reinout van Rees
On 23-03-12 22:00, gowtham wrote: But, i could not get it. It prints the primary key of the stored object rather than the object itself. Well, I don't know what's in the stored object. How are you supposed to print it? Something like {{ my_object.name }}{{ my_object.description }} or so?

Re: Accessing objects from a dictionary in templates

2012-03-23 Thread gowtham
Hi Reinout, Thanks. But, i could not get it. It prints the primary key of the stored object rather than the object itself. Gowthaman On Fri, Mar 23, 2012 at 1:41 PM, Reinout van Rees wrote: > On 23-03-12 20:56, gowtham wrote: > >> >> But, in template, rather than

Re: Accessing objects from a dictionary in templates

2012-03-23 Thread Reinout van Rees
On 23-03-12 20:56, gowtham wrote: But, in template, rather than iterating over the dictionary (using for and items) i would like to access them using keys. You can, can't you? {{ my_dict.some_key }}. You're using numerical keys, which might not work as well. But you can try something like

Accessing objects from a dictionary in templates

2012-03-23 Thread gowtham
Hi Everyone, I am trying to pass a dictionary with numerical as key and a object as value to my template... i construct it like this: reslibdic[res.result_id]=Library.objects.get(libraryresult__result__result_id=res.result_id) But, in template, rather than iterating over the dictionary (using