Flask restless - 关系的搜索过滤器.属性 != 值在一对多关系的情况下



Flask-sqlalchemy 我的操作表的模型是

class Book(db.Model):
    __tablename__ = 'book'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))
    activity = db.relationship('Actions')
class Actions(db.Model):
    __tablename__ = 'actions'
    id = db.Column(db.Integer, primary_key=True)
    book_id = db.Column(db.Integer, db.ForeignKey('book.id'), nullable=False)
    action = db.Column(db.Enum(['requested', 'issued', 'opened', 'closed']), nullable=True)
    created_on = db.Column(db.DateTime, default=_get_date_time)

基本上,这是一本书和行动之间的一对多关系。我正在使用烧瓶不安分的 API 。

我需要得到

所有尚未关闭的书籍

我尝试了以下搜索查询

q={
"filters": [
    {
      "name": "activity",
      "op": "any",
      "val": {
        "name": "action",
        "op": "not_equal_to",
        "val": "closed"
      }
    }
  ]
}

q={
  "filters": [
    {
      "name": "activity",
      "op": "any",
      "val": {
        "name": "action",
        "op": "not_in",
        "val": ["closed"]
      }
    }
  ]
}

但是我得到了错误的结果

{
"num_results": 30,
"objects": [
{
  "activity": [
    {
      "action": "opened",
      "created_on": "2015-06-05T17:05:07",
      "id": 31
    },
    {
      "action": "closed",
      "created_on": "2015-06-05T17:05:44",
      "id": 32
    }
  ],
  "id": 1,
  "name": "K&R"
  ....
},
...
]
"page": 1,
"total_pages": 3
}

是我在这里犯了什么错误,还是这种事情在不安分中是不可能的?

请帮帮我。

试试这个:

q = { "filters":[   
         {
          "name":"activity__action", 
          "op":"not_equal_to", 
          "val":"closed"
         }
      ]
}

相关内容

  • 没有找到相关文章

最新更新