okay, I succeded to get the property I want:

from sqlalchemy import UniqueConstraint
from myproject import model

for constraint in model.User.__table__.constraints:
    if isinstance(constraint, UniqueConstraint):
        for columns in constraint.columns:
            print 'column ' + columns.name + ' has unique contraint'

is there a better way to do that ?

On Jul 22, 11:54 am, Oliver Christen <oliver.chris...@camptocamp.com>
wrote:
> hello all
>
> Im tring to find a way to extract from the model which colums have the
> attribute "unique" set, but after reading the documentation, exploring
> the source code and many many attempts, Im failing miserably.
>
> is there any way to do that?
>
> im using sqlalchemy 0.6.5 with the declarative syntax
>
> class User(Base):
>     __tablename__ = 'user'
>     id = Column(types.Integer, primary_key=True)
>     username = Column(types.Unicode, unique=True, nullable=False)
>
> I would like to be able to find that username has unique = True
>
> from myproject import model
> # do something to find the column with unique=True
> ???
>
> thanks in advance
> best regards
> Oliver

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