Not a good solution but I understand. Let me explain. In web2py models
(and controllers) are not modules and they cannot be imported. If you
want models in modules so that they can be imported you can but you
have to follow some rules:

1) define the tables in a function in a module (not a model file), for
example modules/mymod.py The function must take the db

    def define_tables(db):
        db.define_table('person',Field('name'))
        # etc. etc. etc.

2) call this function from the models and run it.

    mymod=local_import('mymod')
    db=DAL('gae')
    mymod.define_tables(db)

3) Now you can do the same from any normal python module

    from gluon.sql import DAL
    from applications.myapp.modules import mymod
    db=DAL('gae')
    mymod.define_tables(db)

Models are not modules by default (as in other frameworks) because
simply they are not. They require an environment to run into and the
environment depends on a request object.

If the models do not depend on request, response, session, etc. but
they only depend on DAL and Field, you can simply do

    from gluon.sql import DAL, Field
    exec('path/to/model/file.py')

Anyway these are all hacks. the web2py way is to run the scripts using
web2py.py -S -M -R and it may be possible to do it on GAE as well but
I have never tried.


On Dec 16, 11:25 pm, Dan <danbr...@gmail.com> wrote:
> Thanks for the suggestion.
>
> I ended up manually translating the web2py model definition statements
> into GAE style statements. I suppose this happens somewhere in
> web2py's DAL, but I didn't try to figure out where.
>
> On Dec 14, 5:46 pm, Richard <richar...@gmail.com> wrote:
>
> > and as you said, you will need the __init__.py files
>
> > On Dec 15, 8:45 am, Richard <richar...@gmail.com> wrote:
>
> > > try adding your application directory to sys.path
>
> > > On Dec 15, 5:35 am, Dan <danbr...@gmail.com> wrote:
>
> > > > I need to do some bulk operations (eg delete) on data in the GAE
> > > > datastore for a web2py application, and was trying to follow the
> > > > example in the GAE docs 
> > > > here:http://code.google.com/appengine/articles/remote_api.html
>
> > > > I can get the console up and running using the suggested
> > > > appengine_console.py code, but am struggling to think of the right
> > > > command to load the web2py application's data model into the console
> > > > session so that I can run queries and work with the data. For example,
> > > > this didn't work:
>
> > > > >>> import applications.init.models.db
> > > > or
> > > > >>> import models.db
>
> > > > both result in this message:
> > > > ImportError: No module named models.db
>
> > > > What is the proper command? Do I need to create any __init__.py files
> > > > to make it work? Do I need to import some web2py modules first (or
> > > > instead)?
>
> > > > thanks
> > > > Dan
>
>

--

You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.


Reply via email to