ooops... this should be the correct code:

letters=['A', 'B', 'C']
fields=[]
for letter in letters:
        db.define_table(letter, *fields)
fields=[Field(item+'_id', db[item]) for item in letters]

...sorry for the bad code int the previous message.

On 7/6/10, Rick Hultgren <[email protected]> wrote:
> ...so these tables:
>
> db.define_table( 'A',
>  Field( 'A_id',  db.A),
>  Field( 'B_id',  db.B),
>  Field( 'C_id', db.C))
>
> db.define_table( 'B',
>  Field( 'A_id',  db.A),
>  Field( 'B_id',  db.B),
>  Field( 'C_id', db.C))
>
> db.define_table( 'C',
>  Field( 'A_id',  db.A),
>  Field( 'B_id',  db.B),
>  Field( 'C_id', db.C))
>
> ...can be generated with this code:
>
> letters=['A', 'B', 'C']
> fields=[]
>  for letter in letters:
>   db.define_table(letter, *fields)
> fields=[Field(item) for item in letters]
>
> Thanks a lot for the help!
>
> On 7/4/10, mdipierro <[email protected]> wrote:
>> No.
>>
>> Given db.define_table('sometable',*fields), you cannot add fields
>> outside this statement but you can call the statement in a separate
>> http request and add fields to the *fields list.
>>
>> On 4 Lug, 13:45, Rick Hultgren <[email protected]> wrote:
>>> ...with other words -- how to add fields to a table that is already
>>> declared? Is it possible?
>>>
>>> On 7/4/10, Rick Hultgren <[email protected]> wrote:
>>>
>>> > perhaps the table names will be changed, so please don't bother about
>>> > "before" and "after"...the point is -- how to refer/link to the table
>>> > name "locus", when that table is not yet created/declared/made?
>>>
>>> > On 7/4/10, Rick Hultgren <[email protected]> wrote:
>>> >> Thanks for the answers. I'm trying to create these tables:
>>>
>>> >> db.define_table( 'substance',
>>> >>  Field( 'substance',  db.substance),
>>> >>  Field( 'process',  db.process),
>>> >>  Field( 'condition',  db.condition),
>>> >>  Field( 'locus',  db.locus),
>>> >>  Field( 'name'),
>>> >>  Field( 'main_name'))
>>>
>>> >> db.define_table( 'process',
>>> >>  Field( 'substance',  db.substance),
>>> >>  Field( 'process',  db.process),
>>> >>  Field( 'condition',  db.condition),
>>> >>  Field( 'locus',  db.locus),
>>> >>  Field( 'name'),
>>> >>  Field( 'main_name'))
>>>
>>> >> db.define_table( 'condition',
>>> >>  Field( 'substance',  db.substance),
>>> >>  Field( 'process',  db.process),
>>> >>  Field( 'condition',  db.condition),
>>> >>  Field( 'locus',  db.locus),
>>> >>  Field( 'name'),
>>> >>  Field( 'main_name'))
>>>
>>> >> db.define_table( 'locus',
>>> >>  Field( 'substance',  db.substance),
>>> >>  Field( 'process',  db.process),
>>> >>  Field( 'condition',  db.condition),
>>> >>  Field( 'locus',  db.locus),
>>> >>  Field( 'name'),
>>> >>  Field( 'main_name'))
>>>
>>> >> On 7/4/10, mdipierro <[email protected]> wrote:
>>> >>> Could you explain to us in English what you are trying to model? I
>>> >>> am
>>> >>> sure there is a simpler solution using link tables.
>>>
>>> >>> On 3 Lug, 12:14, Rick Hultgren <[email protected]> wrote:
>>> >>>> Thanks for the link. My actual problem is more complicated than the
>>> >>>> example I gave. I realize that I need to link a field to a table
>>> >>>> that
>>> >>>> isn't initiated yet (item2):
>>>
>>> >>>>         objects = ['substance', 'process', 'condition', 'locus']
>>> >>>>         linksubobjects = ['locus', 'before', 'after']
>>> >>>>         unlinksubobjects = ['name', 'main_name']
>>> >>>>         for object in objects:
>>> >>>>                 for item1 in linksubobjects+unlinksubobjects:
>>> >>>>                         for item2 in objects:
>>> >>>>                                 fields=[Field(item1, 'reference
>>> >>>> item2')]
>>> >>>>                                 db.define_table(object,*fields)
>>>
>>> >>>> I suppose the solution would be to initiate the table names and
>>> >>>> then
>>> >>>> add the fields either in db.py, or in the controller file. But I
>>> >>>> have
>>> >>>> no idea how to do this.
>>>
>>> >>>> On 7/3/10, Yarko Tymciurak <[email protected]> wrote:
>>>
>>> >>>> > The online book has a fairly useful search;
>>>
>>> >>>> > For your question, see:
>>> >>>> >http://web2py.com/book/default/section/6/13
>>>
>>> >>>> > Regards,
>>> >>>> > - Yarko
>>>
>>> >>>> > On Jul 3, 8:45 am, Rick <[email protected]> wrote:
>>> >>>> >> Hi,
>>>
>>> >>>> >> I would like to link a table to its own model like this:
>>>
>>> >>>> >>         db.define_table('person',
>>> >>>> >>                 Field('name'),
>>> >>>> >>                 Field('child', db.person))
>>>
>>> >>>> >> I understand that I should first initiate the table and then
>>> >>>> >> link
>>> >>>> >> it
>>> >>>> >> to itself. But how to do that?
>>>
>>> >>>> >> Thanks in advance for help!
>

Reply via email to