You need to pay attention to order, but you can always use
variables... For more examples see Massimo's auditing slice at web2py
slices and make sure to check out the comments... you can var out
fields, table headers and probably more stuff as well like auditing
fields...

Here is a working example with lots of flexibility:

0_init_session_vars_0_uc_admin.py
0_init_settings_0_uc_admin.py
db.py
db_0_field_0_uc_description.py
db_0_field_0_uc_name.py
db_0_field_0_uc_uuid.py
db_0_field_0_uc_title.py
db_1_database_1_uc_admin.py
db_1_database_1_uc_feature.py
db_1_database_1_uc_wiki.py
init_0_add_auth_group_0_uc_admin.py

Sample contents:

# db_0_field_0_uc_uuid.py
####################
# coding: utf8#
try:
    import uuid

except:
    message="/models/db_uc_1_uuid.py ImportError importing uuid"

# uuid generated for this table
uuid = Field('uuid',length=64,readable=False,
writable=False,default=uuid.uuid4())

# uuid reference to another table
owners_uuid = Field('uuid', length=64, readable=False, writable=False)
# readable=False, writable=False

# db_1_database_1_uc_lang.py
####################
# coding: utf8
# ...

db.define_table('lang',      # Available languages
    name,                        # primary language name English
    description,                 # full language description, Canadian
English
    Field('p_code', length=8),             # primary language code:
en, fr, ...
    Field('s_code', length=8),             # secondary language code:
ca, ...
    Field('code', length=17),              # code = p-code + '-' + s-
code: fr-ca
    )


Chris


On Jun 9, 5:21 pm, Binh <[email protected]> wrote:
> Hi,
>
> I am trying to create an orm setup like in ruby on rails with the DAL.
> I have a user, post, and tag model.
> A user has many posts.
> A tag belongs to a user.
> A post has and belongs to many tags.
> A tag has and belongs to many posts.
>
> I have 4 separate files in my models folder: db.py, user.py, post.py,
> and tag.py
> db.py contains the db connection and mail configurations.
> The respective model files define the table structure and have a class
> named after the model to implement virtual fields.
>
> I noticed that defining the tables with relationships in the separate
> files does not work properly.
> The model files would load which appears to be in alphabetical order.
> So, my db.py would load first and then post.py which fails.
> post.py fails to recognize the table definition in user.py, so it
> cannot define the belongs to relationship.
>
> Is their anyway to setup a model file to import all the other models
> without the hassle of file load order and possibly import order which
> rails does implicitly?

Reply via email to