Your query should work fine if you remove the quotes around "scott", I think.
You could also make all of Scott's Pet entities have his entity as their parent:
class Owner(db.Model):
name = db.StringProperty()
class Pet(db.Model):
petname = db.StringProperty()
scott = Owner(name="scott")
scott.put()
Pet(parent=scott, petname="rufus").put()
Pet(parent=scott, petname="fluffy").put()
Pet(parent=scott, petname="snoogums").put()
pets = Pet.all().ancestor(scott).fetch(100)
# Feed pets to your templating engine. So to speak.
By making scott the parent of the Pet entities, they are all added to the same entity group, and the ancestor
query gives you a simple and stragihtforward way to get all of the Pet
entities that are children of the given `Owner'. You should get much better performance with an ancestor query than a non-ancestor query.
This does impose the limitation that the Pet entities can only belong to one entity group, and if you wanted to have a Pet
involved in multiple data relationships, you would have to choose another approach. If it is a one-to-one relationship, just storing a Reference to the other related entity.
To have a printable representation of your Pet
entity, give it a __unicode__
method, something like this:
class Pet(db.Model):
petname = db.StringProperty()
def __unicode__(self):
return "I am " + self.petname
__unicode__
should return a string with the information that you want to see printed by the print
statement. As Nick wisely points out in comments, you should not use print
in an AppEngine application. The SDK comes with Django templates and Jinja2. Use one of those or import one that you prefer.