Google App Engine

The Expando Class

The Expando class is a superclass for data model definitions whose properties are determined dynamically. An Expando model can have a combination of fixed properties similar to Model and dynamic properties assigned to an entity at run-time.

Expando is provided by the google.appengine.ext.db module.

  1. Introduction
  2. Expando()

Expando is a subclass of Model, and inherits its class and instance methods from that class. The Expando class does not define or override any methods.

Introduction

An Expando model can have fixed properties and dynamic properties. Fixed properties behave similar to properties of a Model, and are similarly defined in the Expando model class using class attributes. Dynamic properties are created when they are assigned values on the instance. Two instances of the same Expando class can have different sets of dynamic properties, and can even have dynamic properties with the same name but different types. Dynamic properties are always optional, and have no default value: They don't exist until they are assigned a value.

Dynamic properties cannot use Property instances to perform validation, set defaults or apply automatic logic to values. Dynamic properties simply store values of the supported datastore types. See Types and Property Classes.

Also unlike fixed properties, dynamic properties cannot use a different name for the class attribute and the datastore property name. See Disallowed Property Names.

Tip: If you want to validate a dynamic property value using a Property class, you can instantiate the Property class and call its validate() method on the value.

An Expando subclass can define fixed properties similar to a Model class. Fixed properties of an Expando behave similarly to properties of a Model. An Expando instance can have both fixed and dynamic properties.

import datetime

from google.appengine.ext import db

class Song(db.Expando):
    title = db.StringProperty()

crazy = Song(title='Crazy like a diamond',
             author='Lucy Sky',
             publish_date='yesterday',
             rating=5.0)

hoboken = Song(title='The man from Hoboken',
               author=['Anthony', 'Lou'],
               publish_date=datetime.datetime(1977, 5, 3))

crazy.last_minute_note=db.Text('Get a train to the station.')

An Expando instance's dynamic (non-fixed) properties can be deleted. To delete a dynamic property, an application deletes the instance's attribute:

del crazy.last_minute_note

Constructor

The constructor of the Expando class is defined as follows:

class Expando(parent=None, key_name=None, **kwds)

A model class whose properties do not need to be defined in the class before use. Like Model, the Expando class must be subclassed to define the kind of the data entities.

Expando is a subclass of Model, and inherits or overrides its methods.

Arguments

parent
The Model instance or Key instance for the entity that is the new entity's parent.
key_name

The name for the new entity. The name becomes part of the primary key. If None, a system-generated ID is used for the key.

The value for key_name must not start with a number, and must not be of the form __*__. If your application uses user-submitted data as datastore entity key names (such as an email address), the application should sanitize the value first, such as by prefixing it with a known string like "key:", to meet these requirements.

A key_name is stored as a Unicode string, with str values converted as ASCII text.

**kwds
Initial values for the instance's properties, as keyword arguments. Each name corresponds with an attribute of the new instance, and may either correspond with fixed properties defined in the Expando class, or be dynamic properties.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.