[web2py] Re: record representation format that refer to another table and that table is refer to another table

2019-04-24 Thread Ray (a.k.a. Iceberg)
I know I'm late to the party, but I have to write to thank Anthony for sharing such a wonderful trick! One more thing, I happen to also discover that we do not have to use lambda. The following form is less verbose, more intuitive. db.define_table('room', Field('room_no'), Field('catego

[web2py] Re: record representation and lambda

2015-11-16 Thread Anthony Smith
Thanks Anthony, yes there were some typo's my mistakes On Sunday, 15 November 2015 18:25:01 UTC+11, Anthony Smith wrote: > > Hi All, > > I have looking though the group for and answer on this, I am try to get > the product_name and batch_no from the product table to be the product in > the stock

[web2py] Re: record representation and lambda

2015-11-15 Thread Anthony
> > Traceback (most recent call last): > File "/home/tony/web2py/gluon/restricted.py", line 227, in restricted > exec ccode in environment > File "/home/tony/web2py/applications/cps2d/models/db1.py" > , line 112, in > > d

[web2py] Re: Record representation : multiple levels of references

2014-05-23 Thread Louis Amon
wicked cool thanks a bunch ! On Friday, May 23, 2014 3:28:43 PM UTC+2, Anthony wrote: > > You can use a lambda: > > db.define_table('other_table', > Field('key_id', 'reference key', > requires=IS_IN_DB(db, 'key.id', lambda r: '%s %s (%s)' % (r. > person_id.first_name, >

[web2py] Re: Record representation : multiple levels of references

2014-05-23 Thread Anthony
You can use a lambda: db.define_table('other_table', Field('key_id', 'reference key', requires=IS_IN_DB(db, 'key.id', lambda r: '%s %s (%s)' % (r. person_id.first_name, r. person_id.last_name, r.id Anthony On F

[web2py] Re: Record Representation

2013-07-02 Thread Anthony
The represent attribute does not affect the value stored in the database -- it just affects the display of the value in the grid, SQLTABLE, and read-only forms. If you want to set the value in the database, use a compute field. Anthony On Tuesday, July 2, 2013 3:06:06 PM UTC-4, greenpoise wrot

[web2py] Re: Record representation and SQLFORM.grid searchable

2013-03-31 Thread Anthony
Field('dungeon', 'reference dungeons', required=True, notnull=True, represent=lambda v, r: '(%s %s) %s' % (r.dungeon.mountain.x, r.dungeon.mountain.y, r.dungeon.pos)) This may also work: db.define_table('dungeons', ... format=lambda r: '(%s %s) %s' % (r.mountain.x, r.mount

[web2py] Re: Record representation and SQLFORM.grid searchable

2013-03-31 Thread Vladimir Kaznacheev
ok. may i get representation for *mountain *to be used in representation for *dungeons*? воскресенье, 31 марта 2013 г., 18:39:29 UTC+4 пользователь Anthony написал: > > format='(%(mountain.x)s %(mountain.y)s) %(pos)s' > > If "format" is a string, it can only include the names of fields within >

[web2py] Re: Record representation and SQLFORM.grid searchable

2013-03-31 Thread Anthony
format='(%(mountain.x)s %(mountain.y)s) %(pos)s' If "format" is a string, it can only include the names of fields within the current table (e.g., "mountain"). Anthony On Sunday, March 31, 2013 9:48:47 AM UTC-4, Vladimir Kaznacheev wrote: > > > in *db.py* > db.define_table('mountains', > Fie

[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-23 Thread 黄祥
it works, many thanks, anthony > > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://gro

[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-23 Thread Anthony
Oh, yeah, even better, you can make the "format" attribute a function (it takes a record of its own table) -- so: db.define_table('room', Field('room_no'), Field('category', 'list:string'), Field('status', 'list:string'), Field('branch', 'reference branch'), format=lambda r: '

[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-22 Thread 黄祥
just curious, is it possible to add the format function in the table room? *e.g. 1. no error but the result is not expected* db.define_table('room', Field('room_no'), Field('category', 'list:string'), Field('status', 'list:string'), Field('branch', 'reference branch'), format=l

[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-22 Thread 黄祥
very nice, it's work well, thank you so much for your hints, anthony. just want to share the code that you've guide. def format_room(record): return '%s-%s' % (record.branch.address, record.room_no) def format_booking(record): return '%s-%s %s-%s-%s' % (record.scheduled_start, record.gue

[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-22 Thread Anthony
Sorry, wasn't thinking -- the validator is selecting a record from the "room" table, not the "booking" table, so you'll need a slightly different function for that: IS_IN_DB(..., label=lambda r: '%s %s' % (r.branch.address, r.room_no)) or if want to use a single function (not tested): def form

[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-21 Thread 黄祥
thank you so much for your hint, anthony, but when i test it both of it return an error, any idea about this? IS_IN_DB(db(db.room.status=='Available'), db.room.id, label=lambda r: '%s %s' % (r.room.branch.address, r.room.room_no)) Traceback 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14

[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-21 Thread Anthony
No, IS_IN_DB does not take a "represent" argument, but it does take a "label" argument that works similarly (though the lambda takes only a single argument -- the record): IS_IN_DB(db(db.room.status=='Available'), db.room.id, label=lambda r: '%s %s' % (r.room.branch.address, r.room.roo

[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-21 Thread 黄祥
it's work well, thank you very much anthony. it seems the 'represent' can't work in validators : requires. actually i'm also want the represent format in the form too. when i try to use the represent in requires an error is occured. did you know how to do it in requires field? when using : db.b

[web2py] Re: record representation format that refer to another table and that table is refer to another table

2013-03-21 Thread Anthony
The "format" attribute does propagate, so you'll have to write your own "represent" function for the "room" field (not tested): Field('room', 'reference room', represent=lambda id, r: '%s %s' % (r.room. branch.address, r.room.room_no)) The above represent function uses recursive selects, which I

[web2py] Re: record representation using a non-id column?

2011-07-20 Thread niknok
Thanks Johann! On Jul 20, 8:11 pm, Johann Spies wrote: > On 20 July 2011 14:09, Johann Spies wrote: > > > > > I use this: > > > db.define_table('akb_doccenter_location', > > >                 Field('location')) > > Apologies, I did not complete the message before sending: the model includes > a