Are you saying you want the user to enter a last name for the child and 
then have the drop-down dynamically updated with the list of parents with 
the entered last name? If so, obviously that cannot be done at the time the 
form is generated on the server because you don't know what name the user 
will enter in the form. You'll instead have to handle this with Javascript 
in the browser, possibly with an Ajax call back to the server to populate 
the list (unless the list of parents is small enough to send to the browser 
with the initial page load).

Anthony

On Wednesday, June 11, 2014 6:49:56 AM UTC-4, Mandar Vaze wrote:
>
> On Tue, Jun 10, 2014 at 11:23 PM, Anthony <abasta...@gmail.com> wrote:
>
>> Assuming you have a particular parent last name, it would be:
>>
>> IS_IN_DB(db(db.parent.lname == last_name), 'parent.id', db.parent._format
>> , multiple=True)
>>
>>
> Above would work for a "fixed" last name. But I need it to work with 
> "lambda" - where last_name is same as that of the child
>
> -Mandar
>
>
>
>  
>
>> Anthony
>>
>>
>> On Tuesday, June 10, 2014 12:51:20 PM UTC-4, Mandar Vaze wrote:
>>>
>>>
>>> On Tue, Jun 10, 2014 at 7:53 PM, Anthony <abasta...@gmail.com> wrote:
>>>
>>>> The first argument to IS_IN_DB must be a DAL object or a Set object -- 
>>>> it cannot be a function.
>>>>
>>>
>>> Right, but is there a way to achieve what I am trying to do ? an example 
>>> would help.
>>> Can/should I use IS_IN_SET ? (I got different error mentioned above)
>>>
>>> I think I'm missing something important
>>>
>>> Thanks,
>>> -Mandar
>>>
>>>
>>>
>>>>
>>>> Anthony
>>>>
>>>>
>>>> On Tuesday, June 10, 2014 10:05:21 AM UTC-4, Mandar Vaze wrote:
>>>>>
>>>>> 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 a topic in the 
>>>> Google Groups "web2py-users" group.
>>>> To unsubscribe from this topic, visit https://groups.google.com/d/
>>>> topic/web2py/nDBOL7w6qB4/unsubscribe.
>>>> To unsubscribe from this group and all its topics, send an email to 
>>>> web2py+unsubscr...@googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  -- 
>> 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 a topic in the 
>> Google Groups "web2py-users" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/web2py/nDBOL7w6qB4/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> web2py+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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/d/optout.

Reply via email to