How to make the argument to filter() a variable?

浪尽此生 提交于 2019-12-02 11:45:00
query.filter(self.request.get("tag"), self.request.get("tag"))

The = is actually not required.

However, I'd also consider using a single StringProperty for the tag, since it appears that your 3 string properties are essentially booleans, and only one of them can be true at a time.

Would that do what you're looking for:

choice = self.request.get("tag")
query.filter(choice, choice)

However, I agree with Wooble below. The way you have designed it, you dont' really use glam, casual, speaking as StringProperty, since they are either empty or have a specific value.

What you probably want to do is have a tag property that can take different values from glam, formal, speaking, ...

class Item(db.Model):
    ...   
    tag = db.StringProperty()

And then you would query your db like so:

query.filter("tag", self.request.get("tag"))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!