Thadeus, thanks for the reply. By the way, these are not controllers,
these are models.

Mengu

On Nov 1, 1:53 am, Thadeus Burgess <[email protected]> wrote:
> 2) YES, They need to be in db.py, or another model file, but preferably
> db.py.
>
> 1) will not work. controllers are not python modules, they cannot be
> imported. They are ment to be run in a pre-setup environment by web2py.
>
> The DAL does not know about any tables in the database, unless they are
> specified with "define_table"... Even for tables that exist.
>
> So you cannot split your db table statements up into separate controllers,
> that get called at separate times.
>
> -Thadeus
>
> On Sat, Oct 31, 2009 at 4:07 PM, Mengu <[email protected]> wrote:
>
> > Hi everyone.
>
> > I have db = DAL("sqlite://blog.db") in my db.py. I can define my
> > tables in my models with having that statement in the model however I
> > cannot create relationships.
>
> > For example, this is post.py:
> > db = DAL("sqlite://blog.db")
> > db.define_table('post',
> >    Field('title', 'string'),
> >    Field('body', 'text')
> > )
>
> > and this is comment.py:
> > db = DAL("sqlite://blog.db")
> > db.define_table("comment",
> >    Field('post_id', db.post),
> >    Field('author', 'string'),
> >    Field('comment', 'text')
> > )
>
> > I get the following error:
>
> > Traceback (most recent call last):
> >  File "/home/mengu/projects/web2py/gluon/restricted.py", line 184, in
> > restricted
> >    exec ccode in environment
> >  File "/home/mengu/projects/web2py/applications/blog/models/
> > comment.py", line 5, in <module>
> >    Field('post_id', db.post),
> >  File "/home/mengu/projects/web2py/gluon/sql.py", line 1148, in
> > __getattr__
> >    return dict.__getitem__(self,key)
> > KeyError: 'post'
>
> > I also should note that this works fine if post_id is not db.post but
> > an integer or another field.
>
> > So my questions are:
>
> > 1) Should I import db.post for this to work and how?
>
> > 2) Must table definitions always be made on the db.py file?
>
> > Thanks.
>
> > Mengu
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to