...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=False
>>>
>>> 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=False
>>>
>>> Controller:
>>> def assign_trainers():
>>> trainers=db(db.trianer._is_active==False)
>>> new_dogs=db(db.dogs._is_active==False)
>>> new_dogs.trainer.requires.append(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
>>>
>>>
>>>
>>>
>>> --
>>>
>>>
>>>
>>>
>>
>>
--