Categories
sqlachemy

SQLAlchemy: Filtering a many-to-many on a field but keeping all results of that field

Going Back to Basics In models.py: “”” Basic Product Category models using reference from: https://docs.sqlalchemy.org/en/14/orm/relationship_api.html#sqlalchemy.orm.relationship “”” from sqlalchemy import Column, ForeignKey, Table, Integer, Boolean, String from sqlalchemy.orm import declarative_base, relationship Base = declarative_base() category_products = Table( “category_products”, Base.metadata, Column(“product_id”, ForeignKey(“products.id”), primary_key=True), Column(“category_id”, ForeignKey(“category.id”), primary_key=True), ) class Products(Base): __tablename__ = “products” id = Column(Integer, primary_key=True) label […]