Reputation: 21
How can I get access to the implicit property names of a db.Model in Google App Engine? In particular, assume I have the following:
class Foo(db.Model):
specific = db.IntegerProperty()
class Bar(db.Model):
foo = db.ReferenceProperty(Foo, collection_name = "bars")
if I attempt to get the property names on Foo, like so:
my_foo = Foo(specific = 42)
for key, prop in my_foo.properties().iteritems()
print "HERE bars won't show up"
then the my_foo.bars property doesn't show up. Or am I totally mistaken?
Any help greatly appreciated
edited model to be Python, not ruby
Upvotes: 0
Views: 509
Reputation: 111
(That model definition looks like a strange hybrid of Python and Ruby.)
I'm not clear on what you're trying to achieve here, but you can get a list of model property members using introspection:
[x for x in dir(Foo) if isinstance(getattr(Foo,x), db.Property)]
If you're just trying to add instances of Bar to Foo, you should create new Bar instances with their foo fields pointing at the Foo instance:
foo = Foo(specific=42)
foo.put()
Bar(foo=foo).put()
Bar(foo=foo).put()
logging.info("Foo bars: %r" % list(foo.bars))
Upvotes: 2