[sqlalchemy] DateTime format

2012-08-21 Thread Juan Antonio Ibáñez
Hello, I am using Sqlalchemy under Turbogears and I'd like to know which is the best way to customize column to string conversion of a DateTime column. I need to do it in an automatic way instead having to format it before showing. Regards -- You received this message because you are

[sqlalchemy] Create tables from class declaration

2012-08-21 Thread andrea crotti
The question is probably very simple, but I can't find an answer anywhere... Suppose I already have some tables declarad in a declarative way, as below, how do I create the database schema from them? I usually always did with the meta.create_all() after defining the various Table('name', meta...)

Re: [sqlalchemy] Create tables from class declaration

2012-08-21 Thread Simon King
On Tue, Aug 21, 2012 at 5:25 PM, andrea crotti andrea.crott...@gmail.com wrote: The question is probably very simple, but I can't find an answer anywhere... Suppose I already have some tables declarad in a declarative way, as below, how do I create the database schema from them? I usually

Re: [sqlalchemy] Create tables from class declaration

2012-08-21 Thread andrea crotti
2012/8/21 Simon King si...@simonking.org.uk: The MetaData instance is available via the declarative base class, so you should be able to do something like: Base.metadata.create_all() http://docs.sqlalchemy.org/en/rel_0_7/orm/extensions/declarative.html#accessing-the-metadata Hope that

Re: [sqlalchemy] Create tables from class declaration

2012-08-21 Thread Michael Bayer
On Aug 21, 2012, at 12:50 PM, andrea crotti wrote: 2012/8/21 Simon King si...@simonking.org.uk: The MetaData instance is available via the declarative base class, so you should be able to do something like: Base.metadata.create_all()

[sqlalchemy] Having trouble using classes in different modules with the same name with declarative setup.

2012-08-21 Thread jers
To give an example I have I have two classes that have the same name, but belong to different modules. there is an accounts.py that has a class Account(Base), and a testing.py that has a class Account(Base). When I try to set this up I get warnings: The classname 'Account' is already in the

[sqlalchemy] How do I get an object from a relationship by object's PK?

2012-08-21 Thread Sergey V.
Hi all, I've asked this question on stackoverflow: http://stackoverflow.com/questions/12031861/sqlalchemy-how-do-i-get-an-object-from-a-relationship-by-objects-pk/12032405 Basically, I'm looking for a dict-like access to a relationship to be able to quickly retrieve items by some key (item's

Re: [sqlalchemy] Having trouble using classes in different modules with the same name with declarative setup.

2012-08-21 Thread jers
Good to hear, thanks! On Tuesday, August 21, 2012 5:19:49 PM UTC-4, Michael Bayer wrote: On Aug 21, 2012, at 4:36 PM, jers wrote: To give an example I have I have two classes that have the same name, but belong to different modules. there is an accounts.py that has a class

[sqlalchemy] PG error I don't understand.

2012-08-21 Thread Warwick Prince
Hi I have created a simple update like this on a PG database via PG8000; table=Table('invoice_line_items', meta, autoload=True) query = table.update() query = query.where(and_(eq(table.c.InvBook, 'SC'), eq(table.c.InvNum, 12862), eq(table.c.InvLine, 1))) query = query.values(**data)

[sqlalchemy] Re: Self-Referential Many-to-Many Relationship: related nodes

2012-08-21 Thread adolfo
Hi Michael and all I successfully built a all nodes relationship following your guidelines. As: subq1=select([caso_vinculo.c.caso_1_id.label('id1'),caso_vinculo.c.caso_2_id.label('id2')]).union(select([caso_vinculo.c.caso_2_id, caso_vinculo.c.caso_1_id])) subq2=aliased(subq1) CasoMapper

Re: [sqlalchemy] Self-Referential Many-to-Many Relationship: related nodes

2012-08-21 Thread adolfo
Thanks. The subquery approach works fine. My class is named 'Caso' (Case, in english) I included at the mapper: subq2=aliased(subq1) CasoMapper = mapper(Caso, caso, properties= { 'LinkedNodes':relation(Caso, secondary=subq2,

Re: [sqlalchemy] How do I get an object from a relationship by object's PK?

2012-08-21 Thread Michael Bayer
On Aug 21, 2012, at 5:47 PM, Sergey V. wrote: Hi all, I've asked this question on stackoverflow: http://stackoverflow.com/questions/12031861/sqlalchemy-how-do-i-get-an-object-from-a-relationship-by-objects-pk/12032405 Basically, I'm looking for a dict-like access to a relationship to be

Re: [sqlalchemy] PG error I don't understand.

2012-08-21 Thread Michael Bayer
On Aug 21, 2012, at 6:32 PM, Warwick Prince wrote: Hi I have created a simple update like this on a PG database via PG8000; table=Table('invoice_line_items', meta, autoload=True) query = table.update() query = query.where(and_(eq(table.c.InvBook, 'SC'), eq(table.c.InvNum, 12862),