title: Sqlalchemy declarative inheritance of __table_args__
body: <p>Suppose I have such table</p>
  
  <pre><code>class Base(object):
      id = Column(Integer, primary_key=True)
      date_updated = Column(Date, nullable=True)
      rating = Column(Integer, nullable=False, default=0)
      status = Column(SmallInteger, nullable=False, default=0)
  
      @declared_attr
      def __tablename__(cls):
          return "table_%s" % cls.LANG
  
      @declared_attr
      def __table_args__(cls):
          return (
              Index('ix__%s__rating' % cls.__tablename__, 'rating'),
              Index(
                  'ix__%s__status' % cls.__tablename__,
                  'status',
                  postgresql_where=column('status') == 0,
              ),
              Index(
                  'ix__%s__date_updated' % cls.__tablename__,
                  'date_updated',
                  postgresql_where=column('date_updated') != None,
              ),
          )
  
     class TableEn(Base, db.Model):
         LANG = 'en'
  
  
     class TableUk(Base, db.Model):
         LANG = 'uk'
  </code></pre>
  
  <p>Some way I've found how to create such (partial) indexes as <code>status</code> and <code>date_updated</code> in parent <code>__table_args__</code>. </p>
  
  <p>But I need to create <strong>desc</strong> sorting index <code>rating</code>, like <code>func.desc(rating)</code>, but I do not know how to do that. </p>
  
  <p>None of variants worked for me (variant and it's error):</p>
  
  <ul>
  <li><p><code>Index('ix__%s__rating' % cls.__tablename__, 'rating desc')</code> </p>
  
  <p><strong>KeyError: 'rating desc'</strong></p></li>
  <li><p><code>Index('ix__%s__rating' % cls.__tablename__, cls.rating.desc())</code> </p>
  
  <p><strong>sqlalchemy.exc.ArgumentError: Can't add unnamed column to column collection</strong></p></li>
  <li><p><code>Index('ix__%s__rating' % cls.__tablename__, desc('rating'))</code></p>
  
  <p>while creating schema in db</p>
  
  <p><strong>sqlalchemy.exc.ProgrammingError: (ProgrammingError) syntax error at or near ")"
  LINE 1: CREATE INDEX ix__table_en__rating ON table_en ()</strong></p></li>
  </ul>
  
  <p>Of course I can create that index manually with direct SQL, but I'm sure solution exists somewhere.</p>
  
  <p>Thanks in advance!</p>