What version of web2py are you on? I am on 1.79.2 - and there's no
local variable situation here.
I printed str(v) but it doesn't show the new virtualfield.

gluon.tools.* is already imported in db.py so I haven't added any
import statement for prettydate either.

On Jul 21, 3:05 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> The code you posted works for me but I did found a bug in web2py that
> would cause this problem.
> The bug would show up if you were to import a module of define a local
> variable in added_on(..) and prevent web2py from finding the
> virtualfield.
> I have not fixed the bug in trunk.
>
> Massimo
>
> On Jul 21, 4:37 am, Adi <aditya.sa...@gmail.com> wrote:
>
>
>
> > Hi all,
>
> > I am trying to create a virtual field that returns a pretty date for a
> > given date.
> > [web2py version - 1.79.2]
>
> > db.py
> > -------
> > db.define_table('video', Field('created_on', 'datetime')
> > class DisplayDate():
> > def added_on(self):
> > return gluon.tools.prettydate(self.video.created_on)
>
> > controller
> > --------------
> > db.video.virtualfields.append(DisplayDate())
> > videos=db( some query here).select()
> > return dict(videos=videos)
>
> > view
> > ------
> > {{for v in videos:}}
> > <div>v.video.added_on</div>
>
> > This gives me: KeyError: 'added_on'
>
> > What am I doing wrong? I used this as 
> > reference:http://thadeusb.com/weblog/2009/12/31/web2py_virtualfields_as_an_orm_...

Reply via email to