Ignore my comment... This is Field.Lazy not .Virtual.
Sorry

On Sat, Aug 25, 2012 at 6:29 PM, Marin Pranjić <[email protected]>wrote:

> You don't have to call .get()
> It will be called internally with a row as an argument.
>
> And you should be using row.tablename.fieldname (instead just
> row.fieldname)
>
> Marin
>
>
> On Sat, Aug 25, 2012 at 6:20 PM, Marek Mollin <[email protected]> wrote:
>
>> Still not working.
>> When I add static I can do:
>>
>> >> Test.get(db.test[1])
>> >> 'testobject'
>>
>> This is fine.
>> But I cant do db.test[1].get() as it gives me TypeError - expected at
>> least 1 argument.
>> I thought that if something is defined as Field.Lazy that function
>> automatically gets row as first argument. I mean that's how it works
>> normally with regular functions.
>>
>>
>> W dniu sobota, 25 sierpnia 2012 17:47:14 UTC+2 użytkownik Anthony napisał:
>>
>>> Perhaps you want to use static methods:
>>>
>>> class Test(object):
>>>     @staticmethod
>>>     def get(row):
>>>         return row.name
>>>
>>> Anthony
>>>
>>> On Saturday, August 25, 2012 11:33:06 AM UTC-4, Marek Mollin wrote:
>>>>
>>>> Hello,
>>>>
>>>> I have a problem with a construct like that:
>>>> db.define_table('test',
>>>>     Field('name'),
>>>> )
>>>>
>>>>
>>>> class Test(object):
>>>>     def get(row):
>>>>         return row.name
>>>>     def get_hello(row, greeting):
>>>>         return '%s %s' % (greeting, row.name)
>>>>
>>>>
>>>> db.test.get = Field.Lazy(Test.get)
>>>> db.test.get_hello = Field.Lazy(Test.get_hello)
>>>>
>>>> Why it would not work ?
>>>> It works perfect if its a standard function. But if its unbound method
>>>> I get TypeError expected at least 1.
>>>>
>>>> I am trying to do that in order to better organize models, I do not
>>>> want to go as far as Bruno's modelless aproach as performance is not the
>>>> issue but overtime they become messy. (Also I know that I can just make
>>>> seperate file, but then I have to add number to the file and again it
>>>> becomes very unclean).
>>>>
>>>> The whole deal is to move at least some of the logic to those Lazy
>>>> fields (its a pain to have fat controllers).
>>>>
>>>  --
>>
>>
>>
>>
>
>

-- 



Reply via email to