Skip to content

Instantly share code, notes, and snippets.

@patkujawa-wf
Last active August 29, 2015 14:12
Show Gist options
  • Save patkujawa-wf/1ccc3c11990cda7a289f to your computer and use it in GitHub Desktop.
Save patkujawa-wf/1ccc3c11990cda7a289f to your computer and use it in GitHub Desktop.
Example of using an ndb StructuredProperty, which basically embeds one entity within another
# Taken from http://ae-book.appspot.com/static/pgae-ndb-20121009.pdf
# Video at https://www.youtube.com/watch?v=xZsxWn58pS0
# • StructuredProperty(InnerModelClass)
# • Uses an ndb.Model subclass to model the property value
# • In code, the value is an instance of the model class
# • In the datastore, fields become properties of the main entity, not separate entities
# • Can be queried!
class PlayerHome(ndb.Model):
sector = ndb.IntegerProperty()
house_num = ndb.IntegerProperty()
roof_color = ndb.StringProperty()
class Player(ndb.Model):
# ...
home = ndb.StructuredProperty(PlayerHome)
p1 = Player()
p1.home = PlayerHome()
p1.home.sector = 698714526
p1.home.house_num = 123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment