开发者

Google app engine: reverse reference lookups

Is reverse referencing possible in Google app engine? I am using app engine patch to develope an application and my model is something like:

class Portfolio(db.Model):
   user = db.ReferenceProperty(User)
   pic = db.BlobProperty()

Now, If I have the user objec开发者_开发百科t, is it possible to retrieve the pic associated with the users portfolio? i.e. the reverse reference from the User to Portfolio.


Yes. You can access the pics, via:

user = User()
pics = user.portfolio_set

You can change the default name (which is modelname_set) by passing the collection_name argument to the ReferenceProperty constructor. For example:

class Portfolio(db.Model):
  user = db.ReferenceProperty(User, collection_name="Portfolio")

See more information and examples here: http://code.google.com/appengine/docs/python/datastore/entitiesandmodels.html


Yes it is possible. By default you can access users portfolio through user.portfolio_set. Read here for more info: http://code.google.com/intl/pl/appengine/articles/modeling.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜