Thank Denes you that fixed the attribute error issue.
So in my controller I'm trying to use the fieldMethod to calcluate a sortby
parameter on the fly (not sure if proper approach).
My table is defined as:
db.define_table('Posts',
db.Field('date','datetime',default=request.now,writable=False),
Field.Method('distance',lambda row,
loc_zip=33333:abs(row.zipcode-loc_zip))
)
my controller is:
def func():
...
order=db.Posts.distance(session.zipcode)|db.Posts.date
posts=db().select(db.Posts.ALL,limitby=limitby,orderby=order)
I am getting a "TypeError: 'FieldMethod' object is not callable" error
Also I looked inside web2py code and don't see the or operator defined for
the FielMethod/FieldVirtuals.
If they aren't in the code yet, I wouldn't mind helping with the coding.
I need the functionality for my project anyways.
thanks.
On Monday, December 24, 2012 8:24:02 AM UTC-5, DenesL wrote:
>
> Hi Jeff,
>
> I believe you need web2py 2.3.1 or higher for that.
>
>
>
> On Monday, December 24, 2012 1:36:25 AM UTC-5, Jeff Kusi wrote:
>>
>> I am attempting to use the virtual Methods of the dal but I am running
>> into this issue. Here's my code
>> db.define_table('Posts',
>> db.Field('zipcode'),
>> db.Field.Method('distance',lambda row, loc_zip=33333:abs(
>> row.zipcode-loc_zip))
>> )
>>
>>
>> But I am running into the following error:
>> "AttributeError: type object 'Field' has no attribute 'Method'"
>> I am running
>> web2py™(2, 2, 1, datetime.datetime(2012, 10, 21, 16, 57, 4), 'stable')
>> PythonPython 2.7.3: /home/yolo/python
>> Am I doing something wrong? I looked into the web2py code and all I saw
>> the FieldVirtual method definitions( not Field.Virtual as described in the
>> book).
>> Am I using the wrong version? Any help would be appreciated.
>>
>> thanks.
>>
>
--