I’ve got a question about Google App Engine and querying the datastore.
Suppose I’ve got three classes:
class Animal(db.Model):
age = db.IntegerProperty()
class Giraffe(Animal):
# ...
class Mouse(Animal):
# ...
Now I want to get all the Animal entities. I might try
Animal.all()
But that doesn’t return anything (I created all the Animal entities using the Giraffe and Mouse constructors).
How do I get all the Animal entities? Is the general approach (subclasses of a subclass of db.Modell) ok?
App Engine doesn’t directly support class inheritance, but there’s an extension built into the SDK called PolyModel that does. Modify your Animal class to extend PolyModel instead of Model, and everything will work the way you expect.