On Sat, 10 May 2008 14:06:12 +0530
"Sandesh Singh" <[EMAIL PROTECTED]> wrote:

> It would be best if the auditing columns could be defined in one
> place, and then added to all the tables individually. I believe the
> solution may have more to do with Python than with SQLAlchemy itself.

This is my solution to that very same problem:

    def addTimestamp(table):
        table.append_column(Column('rec_creato', timestamp_t))
        table.append_column(Column('rec_creato_da', username_t))
        table.append_column(Column('rec_modificato', timestamp_t))
        table.append_column(Column('rec_modificato_da', username_t))

    ...
    
    mytable = Table('mytable', metadata,
        Column('id, smallid_t, primary_key=True),
        ...
        )
    addTimestamp(mytable)

I use Postgres, and all my tables "inherits" from a "timestamped"
abstract table that contains those fields. I did try to use an
equivalent setup also for the SA definition, by subclassing
Table... but ran into strange issues: a demo session was getting
closer, so I went for the above solution.

I have another little issue with that: I'd like to be able to say that
those fields behave like a readonly and database-generated value (they
are effectively overwritten by a database trigger, at insert/update
time), possibly without resorting to marking them "defer" on each
mapped entity... Any magical shortcut to achieve that? :-)

hth,
ciao, lele.
-- 
nickname: Lele Gaifax    | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas    | comincerò ad aver paura di chi mi copia.
[EMAIL PROTECTED] |                 -- Fortunato Depero, 1929.

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