Given the following:

from pydal import DAL
from pydal.objects import Field, FieldMethod, FieldVirtual
from qlf import util
ccfg = util.Config()

db = DAL(ccfg.connect_db.dal_string, migrate=False, pool_size=5)
db.define_table('workorder',
                Field('parent_workorder', 'reference workorder'),
                Field('product'),
                Field('quantity', 'decimal(11,2)'))

db.workorder.children = Field.Virtual(lambda row: 
db(db.workorder.parent_workorder 
== row.id).select())

wo = db.workorder(248222)
print(wo.children)


...I get this when I run the code:

Traceback (most recent call last):
  File "/home/jim/dev/miscellaneous/projects/scratch/virtual_fields_test.py"
, line 15, in <module>
    print(wo.children)
  File "/home/jim/.local/lib/python2.7/site-packages/pydal/objects.py", 
line 167, in __getattr__
    raise AttributeError
AttributeError

What I'm trying to do is get a list of all child workorders for a specific 
workorder.

I've also tried using Field.Method and calling as a function, but get an 
attribute error as well.

Anyone have experience with Virtual Fields?  I haven't used them in or out 
of web2py yet but am interested.  Basically, I'm trying to reproduce the 
'backref' behavior from SQLAlchemy.

Thanks for any help

-Jim

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/17fb676e-a241-44c1-ba8f-2d1968669a13%40googlegroups.com.

Reply via email to