I've defined a model that represents the results of a SELECT statement that joins multiple tables together and performs calculations on the columns
from sqlalchemy import select
class ComplexModel(Base):
__table__ = select([users_table.c.id, users_table.c.name, orders_table.c.total]).\
select_from(users_table.join(orders_table, users_table.c.id == orders_table.c.user_id))
and can use it like:
session.query(ComplexModel).filter(ComplexModel.name == "John").first()
How can I provide an interface that allows an IDE to detect the column names of a complex model is to define the columns as class-level attributes:
class ComplexModel:
id = Column(Integer)
name = Column(String)
total = Column(Float)
errors:
"Can't add additional column 'id' when specifying __table__"
I tried using a view:
same as above but:
__table__ = create_view(
name="users-orders-view",
selectable=select(...
But still:
Can't add additional column 'id' when specifying __table__