No, I don't think populate looks at the compute attribute -- it just looks 
at the field type and generates an appropriate value.

On Monday, January 16, 2012 3:21:16 PM UTC-5, tsvim wrote:
>
> Could be it works, but for populate it doesn't. I was hoping to generate a 
> rule that would force populate to behave correctly.
> For the user I can obviously deal with it in AJAX. Is it possible that 
> populate disregards the compute field?
>
> Tsvi Mostovicz
> [email protected]
> www.linkedin.com/in/tsvim
>
>
>
> On Mon, Jan 16, 2012 at 08:35, Anthony <[email protected]> wrote:
>
>> db.define_table('accounts',
>>>                 Field('name','string'),
>>>                 Field('parent_account','**reference accounts'),
>>>                 Field('account_type','string')**)
>>>
>>> What I'm trying to achieve is to create a tree-like structure. So we 
>>> have 5 "root" accounts, which can each hold some sub-accounts etc.
>>> Now the account_type must be the same for all the children of a certain 
>>> account. So the root accounts pre-determine all of the children's account 
>>> type, rendering it unwritable for a child account.
>>> For some reason the following didn't work for me:
>>>
>>> account_types = ['a','b','c']
>>> db.accounts.account_type.**requires  = IS_IN_SET(account_types)
>>> db.accounts.account_type.**required  = True
>>> db.accounts.account_type.**compute = lambda x: 
>>> x['parent_account'].account_**type
>>> db.accounts.account_type.**writeable = lambda x: (x['parent_account'] 
>>> == 0)
>>>
>>
>> For the "compute" attribute, maybe:
>>
>> db.accounts.account_type.compute = lambda r: 
>> db.accounts[r.parent_account].account_type if r.parent_account else None
>>
>> However, I don't think you can set the "writeable" attribute this way 
>> because you won't know if a parent account is going to be specified until 
>> after the new record is submitted, which happens after you have to decide 
>> whether to make the account_type field writeable. Instead you might need 
>> some client side JS and Ajax to dynamically set the account_type if the 
>> user selects a parent_account in the form.
>>
>> Anthony
>>
>>
>

Reply via email to