To see what the set return :

print db((~db.trainer.id.belongs(db()._select(db.dogs.trainer))))

When you will be into the web2py shell.

Richard

On Tue, Aug 28, 2012 at 10:22 AM, Richard Vézina <
[email protected]> wrote:

> Hi Bill,
>
> Did you try you set into the web2py shell to see if it returns something?
>
> I usually try my query in a terminal web2py shell to make sure my query
> are good before waisting time in navigator reloading page.
>
> Here how you can start a web2py shell :
>
> cd into the web2py folder
>
> Than :
>
> python web2py.py -a 'tempory_pwd' -i 127.0.0.1 -p 8001 -S appname -M auto
>
> Under linux... It should be similar under windows.
>
> Richard
>
>
> On Mon, Aug 27, 2012 at 9:57 PM, Bill Thayer <[email protected]> wrote:
>
>> ...no trainers are being returned. I even tried moving
>> unassignedtrainers = (~db.trainer.id.belongs(db()._select(db.dogs.trainer
>> )))
>> db.dogs.trainer.requires = IS_IN_DB(db(unassignedtrainers), 'trainer.id',
>> '%(name)s',zero=T('choose one'))
>>
>>
>> to the controller. No luck.
>>
>> The drop down boxes do not appear,
>> If I click the edit link there are no trainers to select.
>>
>> Tried Richards line to get the trainers without dogs as well.
>>
>> Am I making this harder than it has to be?
>>
>> On Monday, August 27, 2012 2:49:22 PM UTC-5, Bill Thayer wrote:
>>>
>>> Thank you Richard,
>>>
>>> I'll try it as soon as I finish my current round of debugging.
>>>
>>> -Bill
>>>
>>> On Monday, August 27, 2012 1:20:49 PM UTC-5, Richard wrote:
>>>>
>>>> Hello,
>>>>
>>>> If I resume correctly you want to assign a trainer to a dog only if the
>>>> trainer haven't been assign to any dogs yet?
>>>>
>>>> So, what you have to do it to build a set instead of only define an
>>>> simple IS_IN_DB()...
>>>>
>>>> I would do something like this (not tested) :
>>>>
>>>> not_assign_yet_trainer_set = db(~db.trainers.id.belongs(**db(db.dogs.id
>>>> >0).select(db.**dogs.trainer, distinct=True)))
>>>>
>>>> Than you only have to use your set instead of db.trainers in the
>>>> IS_IN_DB() where you normally define the db table to use.
>>>>
>>>> Does it help?
>>>>
>>>> Richard
>>>>
>>>> On Mon, Aug 27, 2012 at 1:12 PM, Bill Thayer <[email protected]> wrote:
>>>>
>>>>> Tryin to use the example shown in Validators between classical and
>>>>> professional 
>>>>> usage<http://web2py.wordpress.com/category/web2py-validators/>to change 
>>>>> the values and widget for an SQLFORM.grid.
>>>>>
>>>>> I need to display an "Assign Trainers" page with an SQLFORM.grid (or
>>>>> something similar) of new dogs that have not been assigned to a trainer 
>>>>> but
>>>>> can only be assigned to new trainers that have not been given dogs. So I
>>>>> thought simple query the is_active property on both cases, append the
>>>>> validator make (& process) my form.
>>>>>
>>>>> db.define_table('trainer',
>>>>>     Field('name'),
>>>>>     Field('specialty'),
>>>>>     auth.signature,
>>>>>     format='%(name)s')
>>>>> db.trainer.is_active.default=F**alse
>>>>>
>>>>> db.define_table('dogs',
>>>>>     Field('name'),
>>>>>     Field('bites', 'boolean'),
>>>>>     Field('trainer', 'reference trainer',
>>>>>               default=1,
>>>>>               widget=SQLFORM.widgets.options**.widget,
>>>>>               requires=[IS_IN_DB('db.**trainer',
>>>>>               IS_UPPER())]),
>>>>>     auth.signature,
>>>>>     migrate=True)
>>>>>
>>>>> db.dogs.is_active.default=Fals**e
>>>>>
>>>>> Controller:
>>>>> def assign_trainers():
>>>>>     trainers=db(db.trianer._is_**active==False)
>>>>>     new_dogs=db(db.dogs._is_active**==False)
>>>>>     new_dogs.trainer.requires.appe**nd(IS_IN_SET(trainers))
>>>>>
>>>>>     grid = SQLFORM.grid(new_dogs)
>>>>>
>>>>>     return locals()
>>>>>
>>>>> Been working on this solution for two days now. Read all the books,
>>>>> bought the 
>>>>> Cookbook<https://play.google.com/books/reader?id=cwjpG47z_7IC&printsec=frontcover&output=reader&authuser=0&hl=en&pg=GBS.PA1>read
>>>>>  the blogs and now I'm out of time with my prototype presentation due
>>>>> Thursday.
>>>>>
>>>>> ANY help is very much needed at this point.
>>>>>
>>>>> Thank you,
>>>>> Bill
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>  --
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>  --
>>
>>
>>
>>
>
>

-- 



Reply via email to