when using default 'list:reference mytable' all the entries from mytable 
are shown in the dropdown (when using SQLFORM.grid)
I want to show the list in the drop down after applying some filters

Here is an example :

db.define_table('parent',
                Field('fname', 'string'),
                Field('lname', 'string'),
                format='%(fname)s %(lname)s'
                )

def get_parents(lname):
    return db(db.parent.lname == lname)

db.define_table('child',
                Field('first_name', 'string'),
                Field('last_name', 'string'),
                Field('parents', 'reference parent', 
                      requires=IS_IN_DB(lambda row: get_parents(row.child.
last_name), 'parent._format')),
                format='%(fname)s %(lname)s'
                )


Here the idea is the when associating an entry from parent table - only 
those values are shown where last name of child matches that of the parent
Obviously the example is "made up" - real scenario is bit complicated - but 
I am getting following error : 

AttributeError: 'function' object has no attribute 'db'



web2py™ Version 2.9.5-stable+timestamp.2014.03.16.02.35.39

Traceback

Traceback (most recent call last):
File "/path/to/web2py/gluon/restricted.py", line 220, in restricted
exec ccode in environment
File "/path/to/web2py/applications/parents/controllers/appadmin.py" 
<http://127.0.0.1:8080/admin/default/edit/parents/controllers/appadmin.py>, 
line 674, in <module>
File "/path/to/web2py/gluon/globals.py", line 385, in <lambda>
self._caller = lambda f: f()
File "/path/to/web2py/applications/parents/controllers/appadmin.py" 
<http://127.0.0.1:8080/admin/default/edit/parents/controllers/appadmin.py>, 
line 153, in insert
form = SQLFORM(db[table], ignore_rw=ignore_rw)
File "/path/to/web2py/gluon/sqlhtml.py", line 1151, in __init__
inp = self.widgets.options.widget(field, default)
File "/path/to/web2py/gluon/sqlhtml.py", line 273, in widget
options = requires[0].options()
File "/path/to/web2py/gluon/validators.py", line 559, in options
self.build_set()
File "/path/to/web2py/gluon/validators.py", line 531, in build_set
table = self.dbset.db[self.ktable]
AttributeError: 'function' object has no attribute 'db'

I am OK to use "list:string" with IS_IN_SET() as well - but I am unable to 
use "lambda row: get_parents(row.child.last_name)"
I get "function is not iterable" error (Off course I will change 
get_parents() function to return list of strings based on my query)

-Mandar

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to