HI, 

I must have skipped _and, it's what i was looking for. But also started 
wondering about second example, but it gives me empty results on drop-down. 
When i remove "~" it works as expected returning IPs that have been already 
assigned.

db.server.ipaddress_id.requires = 
IS_IN_DB(db(~db.ipaddress.id.belongs(db(db.server.id>0)._select(db.server.ipaddress_id))),db.ipaddress.id)

On Saturday, 25 April 2015 20:54:52 UTC+2, Niphlod wrote:
>
> You should read the section on database validators .... 
> http://web2py.com/books/default/chapter/29/07/forms-and-validators#Database-validators
>
> you can either use the _and argument of IS_IN_DB, but more easily for 
> everybody, e.g. there's not even a chance they can select an ip that is 
> used yet, you can just pass a set instead of the whole table to IS_IN_DB...
>
> db(~db.ipaddress.id.belongs(db(db.server.id
> >0)._select(db.server.ipaddress_id)))
>
> On Saturday, April 25, 2015 at 5:28:16 PM UTC+2, kecajk...@gmail.com 
> wrote:
>>
>> Hi Guys, 
>>
>> I have simple database:
>>
>> db.define_table('ipaddress',
>>    Field('ip', unique=True, length=200),
>>    Field('subnet', length=200),
>>    format = '%(ip)s')
>>
>> db.define_table('server',
>>    Field('servername', length=200),
>>    Field('port', length=200),
>>    Field('ipaddress_id', 'reference ipaddress'))
>>
>> I have few records in ipaddress table and not would like to add some 
>> validators. 
>> When adding record to server table i would like to check if ipaddress_id 
>> exist in ipaddress table AND if it hasn't been used before in server table.
>> That can be done by doing:
>>
>> db.server.ipaddress_id.requires = IS_IN_DB(db,db.ipaddress.id, '%(ip)s') 
>> ,IS_NOT_IN_DB(db,db.server.ipaddress_id, '%(ip)s')]
>>
>> But in that case Filed server.ipaddress_id is not a dropdown menu and 
>> it's not presented as %(ip)s. I would like to have dropdown to choose IP 
>> available in ipaddress table, but just the one which hasn't been used 
>> before. Any tips? 
>>
>> Thanks, 
>>
>>

-- 
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