The second parameter of IS_IN_DB should be a set not a query:

query: (geo_item.f_collection_id == geo_collection.id) 
<http://www.google.com/url?q=http%3A%2F%2Fgeo_collection.id&sa=D&sntz=1&usg=AFQjCNFKYqrLLUpXGgMWWpsqg_8EV2f2zg>
set: db(geo_item.f_collection_id == geo_collection.id) 
<http://www.google.com/url?q=http%3A%2F%2Fgeo_collection.id&sa=D&sntz=1&usg=AFQjCNFKYqrLLUpXGgMWWpsqg_8EV2f2zg>

IS_IN_DB(db, db(geo_item.f_collection_id == geo_collection.id 
<http://www.google.com/url?q=http%3A%2F%2Fgeo_collection.id&sa=D&sntz=1&usg=AFQjCNFKYqrLLUpXGgMWWpsqg_8EV2f2zg>
),...)

Been there, done that. Not so easy to spot.


On Thursday, October 1, 2015 at 9:44:56 PM UTC-4, John Smidt wrote:
>
>
> Im currently creating a website for a geology museum. Each exhibit in the 
> museum contains different collections (or categories) of minerals, and each 
> collection has a handful of individual minerals that are being shown at 
> this museum. The part that I am currently working on is to allow an admin 
> to select a featured image of a specific item in each collection via a drop 
> down box within the collection table. However, the validation of this field 
> is acting up. Here is the code:
>
> db.geo_collection.f_featured_img.requires=IS_IN_DB(db, 
> (geo_item.f_collection_id == geo_collection.id 
> <http://www.google.com/url?q=http%3A%2F%2Fgeo_collection.id&sa=D&sntz=1&usg=AFQjCNFKYqrLLUpXGgMWWpsqg_8EV2f2zg>),lambda
>  
> row: '%s' % row.f_name)
>
> The comparison in this line of code (geo_item.f_collection_id == 
> geo_collection.id) is not working, stating that I am unpacking too many 
> values. 
>
> Here is the traceback:
>
> Traceback (most recent call last):
>   File "/home/SIRI/web2py/gluon/restricted.py", line 217, in restricted
>     exec ccode in environment
>   File "/home/SIRI/web2py/applications/mqr/models/db_wizard.py" 
> <https://siri.pythonanywhere.com/admin/default/edit/mqr/models/db_wizard.py>, 
> line 148, in <module>
>     db.geo_collection.f_featured_img.requires=IS_IN_DB(db, 
> (db.geo_item.f_collection_id == db.geo_collection.id),lambda row: '%s' % 
> row.f_name)
>   File "/home/SIRI/web2py/gluon/validators.py", line 497, in __init__
>     (ktable, kfield) = str(field).split('.')
> ValueError: too many values to unpack
>
>
> I believe that the tuple "(ktable, kfield)" is the reason why I'm 
> unpacking too many values, since it requires one table and one field, and I 
> have a table and *two* fields. The question that I have is 
> *how can I reference these items in my table without breaking the code?*
> Some extra info, I have tried to change the IS_IN_DB to IS_IN_SET, but 
> received an error stating that "<type 'exceptions.TypeError'> 'Query' 
> object does not support indexing".
>
> Any information would be greatly appreciated.
> Thank you,
> John
>

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