Lukasz Szybalski wrote: > On Thu, Jul 10, 2008 at 11:26 AM, Heston James - Cold Beans > <[EMAIL PROTECTED]> wrote: >>> Session.add is a version 0.5 method, you're maybe running 0.4.6? >>> >>> In the 0.4.x series, it's going to be: >>> >>> Session.save() for objects that are to be newly added to the session >>> Session.update() for objects that are already in the session, or >>> Session.save_or_update() to have the library figure it out as it does for >> Session.add in v0.5.x >> >> Hi Rick, >> >> That's exactly what the problem was :-) Is there any reason I should avoid >> using 0.5? I'm running python 2.4 at the moment, are they compatible? >> >> Next quick question: I have a habbit of using 'created' and 'modified' >> columns on my tables, is there any way in which I can have the ORM update >> the dates for me when creating and modifying rows? >> > > From the link I sent you previously: > > sqlalchemy.Column('CreatedDate', sqlalchemy.Date, > default=datetime.now().date()), > sqlalchemy.Column('CreatedTime', sqlalchemy.Time, > default=datetime.now().time())
Not so much. That'll stamp every inserted row with the same time- whatever time it was when python evaluated the Table definition. Here's a cross-db way to get timestamps: from sqlalchemy import Table, Column, DateTime, func Table('abc', metadata, ... Column('created', DateTime, default=func.now()), Column('updated', DateTime, onupdate=func.now())) You can set both default= and onupdate= on the same Column if you want 'updated' to be non-NULL on insert. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---