Great. Thank you. (of course it would be much easier, if use of explicit requires= will cause nothing with implicit represent=)
But in one detail it must be different as your version: If I try Field('parent_id', db.parent, requires=IS_IN_DB(db, db.parent.id), represent=lambda id, r: db.parent._format % db.parent(id) if id else '') this works well in appadmin, however it causes internal error in smartgrid: File "C:\Python27\Lib\site-packages\web2py_2_8_2\web2py\gluon\sqlhtml.py", line 2764, in smartgrid user_signature=user_signature, **kwargs) File "C:\Python27\Lib\site-packages\web2py_2_8_2\web2py\gluon\sqlhtml.py", line 2450, in grid value = field.represent(value, row) File "C:\Python27\Lib\site-packages\web2py_2_8_2\web2py\gluon\sqlhtml.py", line 2708, in <lambda> field.represent = lambda id, r=None, referee=referee, rep=field.represent: A(callable(rep) and rep(id) or id, cid=request.cid, _href=url(args=['view', referee, id])) TypeError: <lambda>() takes exactly 2 arguments (1 given) This looks like proper solution: Field('parent_id', db.parent, requires=IS_IN_DB(db, db.parent.id), represent=lambda id: db.parent._format % db.parent(id) if id else '') So - your solution, but lambda with 1 parameter only. Thanks, Mirek Dne pátek, 14. února 2014 0:26:45 UTC+1 Anthony napsal(a): > > If you don't explicitly specify a validator for a reference field and the > referenced table has a "format" attribute, then you get a default validator > *and* a default "represent" attribute (the "represent" attribute is what > is used for read-only displays). However, if you explicitly specify your > own validator, then you no longer get the default "represent" attribute > either, and so you must explicitly provider your own. You could do > something like: > > Field('myfield', 'represent othertable', requires=..., > represent=lambda id, r: db.othertable._format % db.othertable(id) ifid > else '') > > Anthony > > On Thursday, February 13, 2014 6:08:55 PM UTC-5, Mirek Zvolský wrote: >> >> As user of my application I don't want see any ID's at all - instead I >> want always see record content formatted from format=.. >> >> In smartgrid I am able to receive records instead of ID's only, if I run >> with default validator for foreign key (i.e. without requires=..) >> In such case (without requires=..) I see related records for readonly >> foreign keys (View) and for readwrite foreign keys (Edit). >> If I use requires=.. then for readonly foreign keys I see ID's and I have >> no idea, how to prevent it. >> >> If I need a foreign key, which should be None for some records, then I >> think it is necessary to use requires=IS_EMPTY_OR(IS_IN_DB(db, >> db.parent.id)) >> However this will display ID's instead of formatted records for readonly >> foreign keys. :((( >> >> How to do it proper? Can represent=.. help? Or....? >> >> I try it with 2.8.2 version. Thanks for help ! >> (Note: I don't know, if answer to my question was same in older versions, >> or if it has changed in 2,8.2 with new constraint handling for SQLite.) >> >> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- 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://groups.google.com/groups/opt_out.