Cool - thanks guys.  This is exactly what I wanted to know.  Thanks
for the tip about DAL's upper() too.  I'll have to dig around in there
and see what else it can do (I'm obviously new to web2py).  The
upper() thing was just the simplest example I could think of at the
time.  In my actual code, I have another function defined in models.py
that handles the formatting so I think calling represent() on the the
field is exactly what I need.

-jon

On Oct 25, 6:48 am, Anthony <[email protected]> wrote:
> You can't do it automatically, but you can always access the represent
> function for a field if needed. For example:
>
> db.foo.bar.represent(stuff[0].bar)
>
> will apply the represent function to stuff[0].bar.
>
> In this case, there is also a DAL function for upper() which can be used in
> selects:
>
> upperbar = db.foo.bar.upper()
> stuff = db().select(upperbar)
> stuff[0][upperbar]
>
> Anthony
>
> On Tuesday, October 25, 2011 5:04:39 AM UTC-4, jon wrote:
>
> > Looking for ideas on how to get the result of a field's repr instead
> > of its raw value when doing a select.  Example:
>
> > db.define_table('foo', Field('bar', represent=lambda x, row:
> > x.upper()))
> > db.foo.insert({'bar':'aaa'})
>
> > then in my controller...
>
> > stuff = db().select(db.foo.ALL)
>
> > The value of stuff[0].bar is 'aaa' but I want 'AAA' (the output of the
> > field's "represent" function).
>
>

Reply via email to