【发布时间】:2022-01-05 09:28:55
【问题描述】:
我遇到了一个非常混乱的情况,我有一对多的关系,我想查询数据,就像我想要所有父表数据一样,但只想从满足 site_id = 100 条件的子表中获取数据。
class Policy(Base):
"""table containing details for Policies"""
__tablename__ = "UmbrellaPolicy"
id = Column(Integer, primary_key=True)
policy_id = Column(Integer, nullable=False, index=True)
user_defined_name = Column(String(255), nullable=True)
孩子是这样的
class Site(Base):
__tablename__ = "Site"
id = Column(Integer, primary_key=True)
policy_id = Column(Integer, ForeignKey("Policy.id"))
site_id = Column(String(32), nullable=False, index=True)
policy = relationship("Policy", backref="sites")
【问题讨论】:
标签: python python-3.x django django-rest-framework