首页 > 解决方案 > 如何让 SQL Alchemy and_ 动态化

问题描述

我将用户输入作为逗号分隔值。

name, grade, admission_number

用户将至少提供其中之一。我需要构建and_()它以使其相应地过滤。

session.query(Student).filter(and_( Student.name == name, Student.grade == grade ))

如果用户只提供学生的姓名,那么上述语句将查找成绩为空字符串的学生。

我需要能够and_根据用户提供的任何值来构建它。

标签: pythonsqlalchemy

解决方案


推荐阅读