{{=item.currency_symbol()}}

I have serious doubt there is any speed up in making this virtual
field lazy. I think it will be slower.

On Mar 16, 6:47 pm, pbreit <[email protected]> wrote:
> I am trying to use lazy virtual fields and cannot seem to get it to work.
> The non-lazy virtual fields work OK.
>
> Also, can someone clear up the desirability of using lazy virtual fields. I
> saw a post where Massimo suggested there was no reason to make them lazy
> despite my understanding that laziness optimizes database access and/or
> performance.
>
> This code:
>
> class ItemVirtualFields(object):
>
>     def currency_symbol(self):
>         def lazy(currency=self.item.currency):
>             if currency in ['USD', 'AUD', 'CAD']:
>                 return '$'
>             elif currency=='GBP':
>                 return '£'
>             elif currency=='EUR':
>                 return '€'
>             else:
>                 return ''
>         return lazy
>
> db.item.virtualfields.append(ItemVirtualFields())
>
> {{=item.currency_symbol}}
>
> Produces this output:
>
>      <function lazy at 0x17403ab0>0.02

Reply via email to