Closed luciman closed 8 years ago
Hi, I use the code in flask sqlalchemy postgresql, and my tables are in schemas
class User(db.Model, UserMixin): __tablename__ = 'user' __table_args__ = {'schema': 'usr'}
when i want to order by a column by clicking
It works fine for me with this example. I just had to use the Model class name in the Foreign key instead of the string term.
class User(Base): """Define a User.""" __tablename__ = 'users' __table_args__ = {'schema': 'main'} id = Column(Integer, primary_key=True) name = Column(Unicode, unique=True) created_at = Column(DateTime, default=datetime.datetime.utcnow) address = relationship('Address', uselist=False, backref=backref('user')) def __unicode__(self): """Give a readable representation of an instance.""" return '%s' % self.name def __repr__(self): """Give a unambiguous representation of an instance.""" return '<%s#%s>' % (self.__class__.__name__, self.id) class Address(Base): """Define an Address.""" __tablename__ = 'addresses' __table_args__ = {'schema': 'main'} id = Column(Integer, primary_key=True) description = Column(Unicode, unique=True) user_id = Column(Integer, ForeignKey(User.id)) def __unicode__(self): """Give a readable representation of an instance.""" return '%s' % (self.id) def __repr__(self): """Give a unambiguous representation of an instance.""" return '<%s#%s>' % (self.__class__.__name__, self.id)
Thanks for answering. I'm using datatables just for the User table (without join) and it doesn't work.
In order to make it work I had to insert at line 321 the following:
321
if hasattr(parent, '__table_args__'): schemaname = parent.__table_args__["schema"] tablename='%s.%s' % (schemaname, tablename)
It would be nice if you could make a Pull Request with some tests or examples, please
Hi, I use the code in flask sqlalchemy postgresql, and my tables are in schemas
when i want to order by a column by clicking
It works fine for me with this example. I just had to use the Model class name in the Foreign key instead of the string term.
Thanks for answering. I'm using datatables just for the User table (without join) and it doesn't work.
In order to make it work I had to insert at line
321
the following:It would be nice if you could make a Pull Request with some tests or examples, please