python - Flask reSTLess 无法构造查询

标签 python flask sqlalchemy flask-sqlalchemy flask-restless

我有两个 Flask-SQLAlchemy 模型和各自的 Flask-ReSTLess API 端点,如下所示:

class Person(db.Model):
    person_id = db.Column(db.Integer, primary_key=True)
    document = db.Column(db.String(), unique=True)
    name = db.Column(db.String(45))

class Student(db.Model):
    student_id = db.Column(db.Integer, primary_key=True)
    person_id = db.Column(db.Integer, db.ForeignKey('person.person_id'))
    code = db.Column(db.String(45))

    person = db.relationship('Person', backref=db.backref('students', lazy='dynamic'))

manager.create_api(Person, methods=['GET', 'POST'])
manager.create_api(Student, methods=['GET', 'POST'])

这些 URL 工作正常:

  • http://localhost:8080/api/person
  • http://localhost:8080/api/student

但是当我尝试按照 official docs 中所述对相关模型进行搜索查询时,我收到这些请求的 { "message": "Unable to Construction query"}:

  • http://localhost:8080/api/person?q={"filters":[{"name":"students__code","op":"eq","val": “1”}]}

  • http://localhost:8080/api/person?q={"filters":[{"name":"students","op":"has","val": {"name":"code","op":"eq","val":"1"}}]}

  • http://localhost:8080/api/student?q={"filters":[{"name":"person__document","op":"eq","val": “111”}]}

  • http://localhost:8080/api/student?q={"filters":[{"name":"person","op":"any","val": {"name":"document","op":"eq","val":"111"}}]}

我正在使用 Flask 0.10.1、Flask-SQLAlchemy 2.0、Flask-ReSTLess 0.17.0、SQLAlchemy 1.0.6 和 Python 2.7。

最佳答案

查询中的数值不应加引号。

错误:

"val":"1"

正确:

"val":1

关于python - Flask reSTLess 无法构造查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31199439/

相关文章:

python - 每小时高效地将数据从数据存储导入到 BigQuery - Python

python - Flask session 不会持续

python - 如何按列对多维数组进行排序?

python - anaconda环境无法卸载包

python - 在 flask 中使用 HTTP 身份验证时的标准 401 响应

python - 处理表单之间的数据

python - 多处理/psycopg2 TypeError : can't pickle _thread. RLock 对象

python - polymorphic_on 可以在多于一列上使用吗?

python - SQLAlchemy 连接挂起

python - 如何使用 python-pandas 读取列数不均匀的文本文件?