How to get a Model's collection_names?

2 views
Skip to first unread message

Nickolas Daskalou

unread,
Feb 18, 2010, 10:33:59 PM2/18/10
to Google App Engine
Say I have these Models:

class Model1(db.Model):
  ....

class Model2(db.Model):
  model1 = db.ReferenceProperty(Model1, collection_name = 'model2s')
  ....

class Model3(db.Model):
  model1 = db.ReferenceProperty(Model1, collection_name = 'model3s')
  ....

Would this be the best way to get all of Model1's collection_names?

collection_names = [name for name in dir(Model1) if isinstance(getattr(Model1,name), db.Query)]

Is there a better way?

Nickolas Daskalou

unread,
Feb 19, 2010, 12:31:44 AM2/19/10
to Google App Engine
In fact that code I wrote doesn't work because in the SDK the collection_names are instances of db._ReverseReferenceProperty, not db.Query.

Since "_ReverseReferenceProperty" starts with "_", it's not safe to assume that the collection_names will continue to be instances of db._ReverseReferenceProperty, correct?

Has anyone done something similar that works and is safe to use?
Reply all
Reply to author
Forward
0 new messages