Как получить доступ к аттрибуту класса из sqlalchemy where в Python?

Допустим у нас есть функция с аргументом type_of_check, значение которого является именем одного из аттрибутов класса ProductShop. Как получить доступ к этому аттрибуту в sqlalchemy where? Нужно как-бы "распаковать" type_of_check внутри where, что бы сравнить его с False.

async def get_enabled_shops_and_product_shops(shops_ids: list, type_of_check: str) -> list:
query = select(ProductShop). \
    where(and_(ProductShop.shop_id.in_(shops_ids),
               ProductShop.**type_of_check is False)). \
    options(selectinload(ProductShop.shop)). \
    options(selectinload(ProductShop.product))

Ответы (1 шт):

Автор решения: Igor
async def get_enabled_shops_and_product_shops(shops_ids: list, type_of_check: str) -> list:
query = select(ProductShop). \
    where(and_(ProductShop.shop_id.in_(shops_ids),
               getattr(ProductShop, type_of_check) == False)). \
    options(selectinload(ProductShop.shop)). \
    options(selectinload(ProductShop.product))

Сработал вариант с getattr()

→ Ссылка