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

后端 未结 2 1524
南旧
南旧 2021-01-28 07:40

I have this model

class Item(db.Model):
    ...   
    glam = db.StringProperty()
    casual = db.StringProperty()
    speaking = db.StringProperty()
         


        
2条回答
  •  时光说笑
    2021-01-28 08:18

    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"))
    

提交回复
热议问题