On Aug 6, 2011, at 7:18 AM, Mike Conley wrote:

> You can get to the column default value.
> 
>     class MyTable(Base):
>         __tablename__ = 'table'
>         id = Column(Integer, primary_key=True)
>         name = Column(String, default='new name')
>         def __init__(self, name=None):
>             if name is not None:
>                 self.name = name
>             else:
>                 self.name = getDefault(self, 'name')
>     def getDefault(instance, colName):
>         col = instance.__table__.c[colName]
>         if col.default is not None:
>             dflt = col.default.arg
>         else:
>             dflt = None
>         return dflt


Mike,

Thanks.  I adapted your code:

def __init__(self):
        for col in self.__table__.c:
                if col.default is not None:
                        self.__setattr__(col.key, col.default.arg)


Mark    

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to