There are 3 classes (tables in the sqlite database):

class Project(DataBase): __tablename__ = 'projects' id = Column(Integer, primary_key=True, autoincrement=True, nullable=False) name = Column(String, nullable=False, unique=True) domain = Column(String, nullable=False) phrases = relationship("Phrase", backref='proj') def __init__(self, name, domain): self.name = name self.domain = domain class Phrase(DataBase): __tablename__ = 'phrases' query_id = Column(Integer, primary_key=True, autoincrement=True, nullable=False) query_text = Column(String, nullable=False) project = Column(Integer, ForeignKey('projects.id'), nullable=False) city = Column(Integer, nullable=False) enable = Column(Boolean, nullable=False, default=True) positions = relationship("Position", backref='keyword') def __init__(self, query_text, project, city): self.query_text = query_text self.project = project self.city = city class Position(DataBase): __tablename__ = 'positions' id = Column(Integer, autoincrement=True, primary_key=True, nullable=False) query = Column(Integer, ForeignKey('phrases.query_id')) date = Column(Date, nullable=False) pos = Column(Integer, nullable=True) rel_page = Column(String, nullable=True) 

I want to make a request to the database and get all the Positions that relate to those Phrase that relate to the project.

I'm trying to do it like this:

 session = Session(bind=engine) start_date = какая-то дата finish_date = какая-то дата proj_id = какой-то id all_proj_pos = session.query(Position).filter(Position.date.between(start_date, finish_date)).filter(Position.keyword.proj.id == proj_id).all() 

Nothing comes of it. Tell me what am I doing wrong?

    0