I have two models:
class Report(Base): __tablename__ = 'report' id = Column(Integer, primary_key=True) class ReportPhoto(Base): __tablename__ = 'report_photo' id = Column(Integer, primary_key=True) report_id = Column(Integer, ForeignKey(Report.id), nullable=False) report = relationship(Report, uselist=False, backref=backref('report_photo', uselist=True))
And I would like to add a column to the report model that indicates if there are records in ReportPhoto. I am trying to use column_property as follows:
class Report(Base): __tablename__ = 'report' id = Column(Integer, primary_key=True) has_photo = column_property( select(ReportPhoto.any()) )
but get an error NameError: name 'ReportPhoto' is not defined . How can I fix this problem?
source share