Performing Foo._properties
should get you access to any attributes you define on your polymodel.PolyModel
that inherit from google.appengine.ext.db.Property
.
This means that KeyProperty
, StringProperty
, etc... will show up in Foo._properties
, so I'm assuming you now need to find all the methods decorated by property
.
Fortunately, this isn't that hard. First, a quick sidetrack into decorators (forgive me if you know this already).
In python decorators are just syntactic sugar. For example, these two methods result in the same thing:
@property
def bar(self):
pass
def bar(self):
pass
bar = property(bar)
Fortunately for us, property(obj)
returns a new property
object. This also means that @property
returns a property
object as well. You can kind of think of property
as a class! And finally can use isinstance(bar, property)
to see if bar
is a property.
Finally, we can put this into use by examining each of Foo
's attributes and selecting only those that are property
instances.
for attr_name, attr_value in Foo.__dict__.iteritems():
if isinstance(attr_value, property):
print attr_name, attr_value
# bar, <property object at ...>