On May 2, 11:02 am, ztd <zac.thompsondav...@gmail.com> wrote:
> Hi,
>
> here is an error I receive in a simple stock tracking application I'm
> making to help me learn Web2Py:
>
> Traceback (most recent call last):
>   File "gluon/restricted.py", line 178, in restricted
>   File "C:\Users\Zac\Desktop\web2py\applications\shares/views\default/
> index.html", line 86, in <module>
> AttributeError: 'Rows' object has no attribute 'asx_code'
>
> I think the problem is to do with passing variables between the
> controller and view. I've based this app on the 'image blog' example
> in the book. Here is my code so far:
>
> ---db.py---
>
> db.define_table('shares',
>     Field('asx_code'),
>     Field('date_added','datetime',default=request.now),
>     Field('quantity'),
>     Field('buy_price'))
>
> db.define_table('prices',
>     Field('share_id',db.shares),
>     Field('date','datetime',default=request.now),
>     Field('price_low',default='0'),
>     Field('price_high',default='0'),
>     Field('price_close',default='0'))
>
> db.shares.asx_code.requires =
> [IS_NOT_EMPTY(),IS_NOT_IN_DB(db,db.shares.asx_code)]

I think the format of your  requres (above) may be your problem - see
http://web2py.com/book/default/section/7/4?search=IS_NOT_IN_DB

Let us know if this solves your problem.

Regards,
- Yarko

> db.shares.quantity.requires = IS_NOT_EMPTY()
> db.shares.buy_price.requires = IS_NOT_EMPTY()
>
> db.prices.share_id.requires = IS_IN_DB(db,db.shares.id,'%(asx_code)s')
>
> db.prices.share_id.writable = db.prices.share_id.readable = False
>
> ---index in default.py---
>
> def index():
>     shares=db().select(db.shares.ALL, orderby=db.shares.asx_code)
>     return dict(shares=shares)
>
> ---default/index.html---
>
> {{extend 'layout.html'}}
> <h1>Share portfolio</h1>
> <ul>
> {{for asx_code in shares:}}
> {{=LI(shares.asx_code)}}
> {{pass}}
> </ul>
>
> What am I doing wrong? i'm a bit confused with variables in the
> controller, I have a table called shares, a variable declared in the
> controller called shares and the value in the dictionary called shares
> so it's very hard to know what I'm calling / using in the view!!! (the
> LI code could be wrong, I couldn't get it to show anything to debug
> that far). shares table contains two entries.
>
> Thanks!

Reply via email to