开发者

Newbie App Engine Datastore question - Models and .filter()

开发者 https://www.devze.com 2023-02-22 08:27 出处:网络
I am currently testing GAE and I am having some trouble adapting to the datastore ... Given the example model:

I am currently testing GAE and I am having some trouble adapting to the datastore ...

Given the example model:

  class Category(db.Model):
      name = db.StringProperty()
      date_time = db.DateProperty(auto_now_add=True)
开发者_JS百科
  class Link(db.Model): 
      category = db.ReferenceProperty(Category, collection_name='links')
      name = db.StringProperty()
      date_time = db.DateProperty(auto_now_add=True)
      link = db.LinkProperty()
      type = db.StringProperty(choices=set(["in", "out"]))

and the not working code:

category = Category.get(key)
link = category.links.filter('type=', 'in').get()

it seems that I am unable to filter() on the referenced property... Strange thing is that category.links is a Query object... It is possible to iterate through category.links and verify the type property but I am certain that there is a better way...

Any help is welcome Thanks in advance


Your code is fine, just put a space between type and =

link = category.links.filter('type =', 'in').get()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号