many ways:

1. use a default on your column (this is the easiest way):

        Column('access_time', DateTime, default=func.now(),  
onupdate=func.now())

2. set it on your instance as a SQL expression (if you need more  
control):

        user.access_time = func.now()
        session.commit()

3. do the same thing but automatically within a mapper extension (if  
you want it automatic, but have some reason you want to do it at the  
ORM level):

        class MyExt(MapperExtension):
             def before_update(self, mapper, connection, instance):
                 instance.access_time = func.now()

         mapper(User, users_table, extension=MyExt())


On Nov 10, 2008, at 1:48 AM, fanlix wrote:

>
> hi:
>  In my app there is a user_table, with a column "access_time".
>  Without sqlalchemy, just "update user_table set access_time =
> Now()" ,
>  With sqlalchemy and user as a object-relational object, I have to
> make a app time and do "user.access_time = now() "?
>
>  or a better way?
>
> >


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to