Thank you, David
I tried your example and SQLAlchemy seems to correctly modify the
objects for linking them.
Now I only need to create tables first. In your case, you probably
manually created them in Postgre. I am trying to follow the wiki20
style and make SQLAlchemy create tables (in Sqlite). At the moment I
am stuck at the point of creating the foreign key. When calling
metadata.create_all (and actually drop_all) SQLAlchemy tells that it
can't create foreign key to the non-existing table.. of course,
because it hasn't been created yet. I wonder how people create linked
tables via SQLAlchemy.
wordpairtopics_table = Table("wordpairtopics", metadata,
Column("id", Integer, primary_key = True),
Column("title", Unicode(100), nullable = False)
)
class WordPairTopic(object):
def __init__(self, title):
self.title = title
wordpairs_table = Table("wordpairs", metadata,
Column("id", Integer, primary_key=True),
Column("sourcetext", Unicode(100), nullable = False),
Column("desttext", Unicode(100), nullable = False),
Column("topic_id", Integer, ForeignKey("
worpairtopics.id"))
)
...
engine = create_engine("sqlite:///testdevdata2.db", echo=True)
DBSession.configure(bind=engine)
# Create the tables
metadata.drop_all(engine)
metadata.create_all(engine)
Best regards,
Artem.
On Jan 9, 11:55 pm, David Gardner <
dgard...@creatureshop.com> wrote:
> Not sure about TG2, but I have been using SQLAlchemy 0.5 against TG
> 1.0.7 for a while now. Note in my case I'm using SQLAlchemy from the
> command line, and then importing my SA code into model.py in TG and
> exposing it as a webapp. I'm not sure I remember why but adding
> 'save_on_init=False' to my mappers fixed something.
>
> from sqlalchemy import *
> from sqlalchemy.orm import *
>
> # Turbogears compatabilityhttp://
www.sqlalchemy.org/docs/04/session.html#unitofwork_contextual
> > it and SQLAlchemy tutorial athttp://
www.sqlalchemy.org/docs/05/ormtutorial.html#building-a-relation
> > seems to be based on a functionality not yet supported (not
> > recommended?) by TG yet. I was able to find some topics about similar
> > things in this group, but it looks like TG and SQLAlchemy evolve
> > faster, than tutorials and discussions :)
>
> > Could anybody, please, post a simple one to many model example?
> > Something that would allow accessing addresses e.g. via the following:
>
> >>>> jack = User('jack')
> >>>> jack.addresses
>
> > []
>
> > Best regards,
> > Artem.
>
> --
> David Gardner
> Pipeline Tools Programmer, "Sid the Science Kid"
> Jim Henson Creature Shop
>
dgard...@creatureshop.com