Not sure if this is the only problem, but when you d do nested select, you 
should select only one column:

set = db.t_image.id.belongs(db(query)._select(db.t_image.id, limitby=(0,48
)))

Anthony

On Monday, June 2, 2014 1:56:30 PM UTC-4, Spokes wrote:
>
> Thanks, Anthony. I'm trying the following:
>
> Model:
>
> query_list = [(db.t_image.created_by == None)]
>
> if session.auth: 
>     query_list.append((db.t_image.created_by == session.auth.user.id))
>
> query = reduce_db_queries(query_list, 'or')
> set = db.t_image.id.belongs(db(query)._select(limitby=(0,48)))
>
> db.define_table('t_gallery',
>     Field('f_images', 'list:reference t_image', label = T('Images'), 
>           requires = IS_IN_DB(set, db.t_image._format, multiple=(1,24) )), 
>     ...)
>
> It produces a "need more than 1 value to unpack" error, associated with 
> line on which the definition of the field ends. The rest of the error 
> message is this:
>
> File C:\web2py\gluon\validators.py in __init__ at line 497 code arguments 
> variables 
>
> Function argument list 
>
> (self=<gluon.validators.IS_IN_DB object>, dbset=<Query (t_image.id IN (SELECT 
> t_image.id, t_ima... = NULL)) ORDER BY t_image.id LIMIT 1 OFFSET 0))>, 
> field='%(f_image_caption)s | %(created_on)s', label=None, 
> error_message='Value 
> not in database', orderby=None, groupby=None, distinct=None, cache=None, 
> multiple=(1, 24), zero='', sort=False, _and=None) 
>
> 493.
> 494.
> 495.
> 496.
> 497.
>
> 498.
> 499.
> 500.
> 501.
>
>
>         if hasattr(dbset, 'define_table'):
>             self.dbset = dbset()
>         else:
>             self.dbset = dbset
>         (ktable, kfield) = str(field).split('.')
>
>         if not label:
>             label = '%%(%s)s' % kfield
>         if isinstance(label, str):
>             if regex1.match(str(label)):
>
>  
> Variables 
>  builtinstr <type 'str'> 
>  field '%(f_image_caption)s | %(created_on)s' 
>  ).split <built-in method split of str object> 
>  ktable undefined 
>  kfield undefined
>
> Any ideas?
>
>
>
>
>
>
>
>
>
> On Monday, June 2, 2014 11:43:56 AM UTC-5, Anthony wrote:
>>
>>
>> Field('images', 'list:reference t_image'),
>>>
>>> I'd like to do the following:
>>>
>>> -make it so that the input for that field cannot be empty upon 
>>> submission, and the number of references the user must select is in some 
>>> range of numbers, (n_min, n_max)
>>>
>>
>> The IS_IN_DB validator takes a "multiple" argument that can either be 
>> True or a tuple with a min and max number of selections:
>>
>> IS_IN_DB(..., multiple=(1,3))
>>
>> -when a *select* element is created from that field (for example, 
>>> through the use of SQLFORM), the *select* should only show references 
>>> created by the user whose *id* matches session 
>>> <http://127.0.0.1:8000/examples/global/vars/session>.auth.user.id; the 
>>> *select* element should only show the last N references submitted by 
>>> that user
>>>
>>
>> The first argument to IS_IN_DB can be a DAL Set object that limits the 
>> set of records. It also takes "groupby" and "orderby" arguments, though 
>> unfortunately not a "limitby" argument (perhaps we should add that) -- so 
>> that's makes it trickier to select the last N submissions. To get around 
>> that problem, I suppose the Set object could include a query like 
>> db.t_image.id.belongs(db([query])._select(..., 
>> limitby=...)).
>>
>> Anthony
>>  
>>
>

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