App Engine Python SDK  v1.6.9 rev.445
The Python runtime is available as an experimental Preview feature.
Public Member Functions | List of all members
google.appengine.ext.db.Expando Class Reference
Inheritance diagram for google.appengine.ext.db.Expando:
google.appengine.ext.db.Model

Public Member Functions

def __init__
 
def __setattr__
 
def __getattribute__
 
def __getattr__
 
def __delattr__
 
def dynamic_properties
 
- Public Member Functions inherited from google.appengine.ext.db.Model
def __new__
 
def __init__
 
def key
 
def put
 
def delete
 
def is_saved
 
def has_key
 
def dynamic_properties
 
def instance_properties
 
def parent
 
def parent_key
 
def to_xml
 
def get
 
def get_by_key_name
 
def get_by_id
 
def get_or_insert
 
def all
 
def gql
 
def from_entity
 
def kind
 
def entity_type
 
def properties
 
def fields
 

Additional Inherited Members

- Static Public Attributes inherited from google.appengine.ext.db.Model
 save = put
 

Detailed Description

Dynamically expandable model.

An Expando does not require (but can still benefit from) the definition
of any properties before it can be used to store information in the
datastore.  Properties can be added to an expando object by simply
performing an assignment.  The assignment of properties is done on
an instance by instance basis, so it is possible for one object of an
expando type to have different properties from another or even the same
properties with different types.  It is still possible to define
properties on an expando, allowing those properties to behave the same
as on any other model.

Example:
  import datetime

  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.')

Possible Uses:

  One use of an expando is to create an object without any specific
  structure and later, when your application mature and it in the right
  state, change it to a normal model object and define explicit properties.

Additional exceptions for expando:

  Protected attributes (ones whose names begin with '_') cannot be used
  as dynamic properties.  These are names that are reserved for protected
  transient (non-persisted) attributes.

Order of lookup:

  When trying to set or access an attribute value, any other defined
  properties, such as methods and other values in __dict__ take precedence
  over values in the datastore.

  1 - Because it is not possible for the datastore to know what kind of
      property to store on an undefined expando value, setting a property to
      None is the same as deleting it from the expando.

  2 - Persistent variables on Expando must not begin with '_'.  These
      variables considered to be 'protected' in Python, and are used
      internally.

  3 - Expando's dynamic properties are not able to store empty lists.
      Attempting to assign an empty list to a dynamic property will raise
      ValueError.  Static properties on Expando can still support empty
      lists but like normal Model properties is restricted from using
      None.

Constructor & Destructor Documentation

def google.appengine.ext.db.Expando.__init__ (   self,
  parent = None,
  key_name = None,
  _app = None,
  kwds 
)
Creates a new instance of this expando model.

Args:
  parent: Parent instance for this instance or None, indicating a top-
level instance.
  key_name: Name for new model instance.
  _app: Intentionally undocumented.
  args: Keyword arguments mapping to properties of model.

Member Function Documentation

def google.appengine.ext.db.Expando.__delattr__ (   self,
  key 
)
Remove attribute from expando.

Expando is not like normal entities in that undefined fields
can be removed.

Args:
  key: Dynamic property to be deleted.
def google.appengine.ext.db.Expando.__getattr__ (   self,
  key 
)
If no explicit attribute defined, retrieve value from entity.

Tries to get the value on the object normally, but failing that
retrieves value from contained entity.

Args:
  key: Name of attribute.

Raises:
  AttributeError when there is no attribute for key on object or
contained entity.
def google.appengine.ext.db.Expando.__getattribute__ (   self,
  key 
)
Get attribute from expando.

Must be overridden to allow dynamic properties to obscure class attributes.
Since all attributes are stored in self._dynamic_properties, the normal
__getattribute__ does not attempt to access it until __setattr__ is called.
By then, the static attribute being overwritten has already been located
and returned from the call.

This method short circuits the usual __getattribute__ call when finding a
dynamic property and returns it to the user via __getattr__.  __getattr__
is called to preserve backward compatibility with older Expando models
that may have overridden the original __getattr__.

NOTE: Access to properties defined by Python descriptors are not obscured
because setting those attributes are done through the descriptor and does
not place those attributes in self._dynamic_properties.
def google.appengine.ext.db.Expando.__setattr__ (   self,
  key,
  value 
)
Dynamically set field values that are not defined.

Tries to set the value on the object normally, but failing that
sets the value on the contained entity.

Args:
  key: Name of attribute.
  value: Value to set for attribute.  Must be compatible with
datastore.

Raises:
  ValueError on attempt to assign empty list.
def google.appengine.ext.db.Expando.dynamic_properties (   self)
Determine which properties are particular to instance of entity.

Returns:
  Set of names which correspond only to the dynamic properties.

The documentation for this class was generated from the following file: