In a declaratively created table, is there an automatic way to get a new 
instance of the class object to be populated with values specified in a 
'default' clause?

i.e.

class MyTable(Base):
        __tablename__ = 'table'
        name = Column(String, default='new name')
        ...


newRow = MyTable()

is there a way to have newRow.name automatically have the value 'new name' 
before it is committed to the database?  The best I've been able to come up 
with so far is to use a 'CONSTANT' in the default clause and use that same 
CONSTANT to initialize the field in the class' __init__, but this doesn't seem 
very DRY.

Or, maybe is this the wrong question?  Maybe I'm trying to do things the wrong 
way. I'm trying to use mostly the same code add a new row or edit an existing 
row.  If the user is adding a record, I create a new instance of the class and 
use the add/edit screen to edit the data. If the user is editing an existing 
row, I retrieve the row, then use the add/edit screen with it.

Thanks,
Mark

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
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