whoa! new word "represent". Doesn't work for me (although no error shown)
Any documentation of what "represent" does? I added the line to the end of my db.py file and accessed using the same v.created_on field - it shows the database date field. On Jul 21, 3:50 pm, "mr.freeze" <[email protected]> wrote: > I wouldn't use a virtualfield for this since you're only interacting > with one field. You can use do: > db.video.create_on.represent = lambda v: gluon.tools.prettydate(v) > > On Jul 21, 5:17 am, Adi <[email protected]> wrote: > > > > > 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 <[email protected]> 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 <[email protected]> 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_...

