>
> Traceback (most recent call last):
>   File "/home/tony/web2py/gluon/restricted.py", line 227, in restricted
>     exec ccode in environment
>   File "/home/tony/web2py/applications/cps2d/models/db1.py" 
> <http://127.0.0.1:8000/admin/default/edit/cps2d/models/db1.py>, line 112, in 
> <module>
>     db.stock_task.product.requires=IS_IN_DB(db,db.product,lambda record: 
> format_product(record))
>   File "/home/tony/web2py/gluon/packages/dal/pydal/base.py", line 906, in 
> __getattr__
>     return super(DAL, self).__getattr__(key)
>
>
The attribute error occurs when trying to access an attribute of the DAL 
object (i.e., db), which implies the problem is in the db.product part of 
the code, not anything to do the the lambda. I notice in the code you show, 
you have defined a table called "product", but in the stock_task table, the 
"product" field is defined as "list:reference products". In your real code, 
is the product table defined as "products" rather than "product"? If so, 
that will result in an attribute error when you try db.product.
 

> db.define_table('product',
>                 Field('product_name'),
>                 Field(batch_no),
>                 format=lambda record: format_product(record))
>
>
Also, note that "batch_no" above is not surrounded by quotes -- if that 
were your actual code, that would throw an error before the line you are 
reporting.

In general, if you are showing some variation of your original code, be 
sure to try that exact variation and ensure it is resulting in the same 
error -- otherwise, it is difficult to diagnose the real problem.
 

>
> def format_product(record):
>     return '%s %s' % (record.product_name, record.batch_no)
>
>
Note, there is no need for this format function -- if all you are doing is 
string formatting, you can simply define:

    format='%(product_name)s %(batch_no)s'

If you need to re-use that somewhere, you can later retrieve it via 
db.product._format. 

db.define_table('stock_task',
>                 Field(........)
>                 Field(........)
>                 Field('product','list:reference products'),
>
>                 auth.signature)
>
> db.stock_task.product.requires=IS_IN_DB(db,db.product,lambda record: 
> format_product(record))
>
>
Note, when creating an IS_IN_DB validator for a list:reference field, you 
should set multiple=True to allow multiple values. Anyway, you shouldn't 
need to do this at all, as you will get exactly this default validator 
automatically as long as the referenced table has a "format" attribute 
defined.

Anthony

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to