Search code examples
pythongoogle-app-enginenesteddatastore

In App Engine for Python, is it possible to persist a class with another object nested inside it?


In App Engine for Python, is there anything like Objectify (Java Library) where I can easily embed a class within another and save it to the datastore?

This class would be modeled like the following example where a Venue contain a Location object. I want to persist this as one nested object, as well as be able to query by fields in the embedded object.

class Location():
  city = db.StringProperty()
  state = db.StringProperty()

class Venue(db.Model):
  name = db.StringProperty()
  location = Location()

Here is information on how it works in Objectify in App Engine for Java.
http://code.google.com/p/objectify-appengine/wiki/IntroductionToObjectify#@Embedded

Is this possible using Python?


Solution

  • Not currently, but the NDB library supports embedding models within one another either by serializing them as Protocol Buffers, or by nesting their properties (Objectify fashion).