Ok, I get how the IS_IN_SET needs a filtered set as the first argument but now I'm not sure how to get the `current_collection_id`? This is all dealing with a SQLFORM.grid and my `.requires` statement is in my model so how do I get the id of the collection that was selected from the grid into my model for the filter?
On Monday, October 12, 2015 at 12:32:08 PM UTC-6, Anthony wrote: > > First, you've got the arguments to IS_IN_DB wrong -- the first argument is > a DAL connection object or a DAL Set object (which is what you want), and > the second is a single field object (or a field name in 'table.field' > format). Second, your query implies a join, but really you just want to > filter f_collection_id based on a single value, so you probably want > something like: > > db.geo_collection.f_featured_img.requires = IS_IN_DB( > db(db.geo_item.f_collection_id == current_collection_id), > db.geo_item.id, ...) > > You'll have to set current_collection_id to the appropriate value. > > Anthony > > > > > On Monday, October 12, 2015 at 12:54:03 PM UTC-4, John Smidt wrote: >> >> Hi, >> I am trying to populate a drop down box so that a user may choose a >> "featured Image" from a collection of images. There are multiple >> collections, so I need to filter out the other images that are in the >> different collections. The code I have is shown below: >> >> 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.id + " - " + row.f_name) >> >> What I had in mind is that the program would go through every item in the >> database, and compare its collection id with the collection's id that we >> are currently looking at. If the item passes this boolean statement, then >> it is added to the dropdown box. >> >> When I do this, it states that there are too many values to unpack. >> Traceback below: >> >> 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 149, 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.id + " - " + 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 thought that using the 'IS_IN_DB' command might be messing with this, >> so I changed it to 'IS_IN_SET'. I got this error instead: >> >> 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/controllers/cms.py" >> <https://siri.pythonanywhere.com/admin/default/edit/mqr/controllers/cms.py>, >> line 478, in <module> >> File "/home/SIRI/web2py/gluon/globals.py", line 372, in <lambda> >> self._caller = lambda f: f() >> File "/home/SIRI/web2py/gluon/tools.py", line 3239, in f >> return action(*a, **b) >> File "/home/SIRI/web2py/applications/mqr/controllers/cms.py" >> <https://siri.pythonanywhere.com/admin/default/edit/mqr/controllers/cms.py>, >> line 26, in display_manage >> oncreate=coll_create,onupdate=coll_create) >> File "/home/SIRI/web2py/gluon/sqlhtml.py", line 2764, in smartgrid >> user_signature=user_signature, **kwargs) >> File "/home/SIRI/web2py/gluon/sqlhtml.py", line 2093, in grid >> update_form = SQLFORM(table, record, **sqlformargs) >> File "/home/SIRI/web2py/gluon/sqlhtml.py", line 1145, in __init__ >> inp = self.widgets.options.widget(field, default) >> File "/home/SIRI/web2py/gluon/sqlhtml.py", line 270, in widget >> options = requires[0].options() >> File "/home/SIRI/web2py/gluon/validators.py", line 428, in options >> items = [(k, self.labels[i]) for (i, k) in enumerate(self.theset)] >> TypeError: 'Query' object does not support indexing >> >> >> Any ideas on how I could do this? I feel like it's a really simple tweak, >> but I'm just not seeing it. Any help would be fantastic. >> >> >> -- 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.

