I am using the Google App Engine polymodel to model data that can have more than one instance of a property - e.g. a contact could have multiple phone numbers. Say this is my setup:
class Foo(polymodel.PolyModel):
some_prop = ndb.StringProperty()
@property
def bar(self):
return Bar.query(Bar.foo == self.key)
class Bar(ndb.Model):
foo = ndb.KeyProperty(kind = Foo)
other_prop= ndb.StringProperty()
(I got this approach after reading this GAE article on data modeling: https://developers.google.com/appengine/articles/modeling)
Now when I do:
Foo._properties
I only get access to the following:
{'some_prop': StringProperty('some_prop'),
'class': _ClassKeyProperty('class', repeated=True)}
Is there any way to access to ALL properties, including those defined with "@property"?
Many thanks for any help or or insight on where I'm going wrong. - Lee
UPDATE: Based on @FastTurle's great answer, I've now added a class method that returns both class properties as well as methods tagged as properties via @property:
def props(self):
return dict(self._properties.items() + \
{attr_name:getattr(self,attr_name) for \
attr_name, attr_value in \
Foo.__dict__.iteritems() if \
isinstance(attr_value,property)}.items())