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.ndb.model.ComputedProperty Class Reference
Inheritance diagram for google.appengine.ext.ndb.model.ComputedProperty:
google.appengine.ext.ndb.model.GenericProperty google.appengine.ext.ndb.model.Property google.appengine.ext.ndb.model.ModelAttribute

Public Member Functions

def __init__
 
- Public Member Functions inherited from google.appengine.ext.ndb.model.GenericProperty
def __init__
 
- Public Member Functions inherited from google.appengine.ext.ndb.model.Property
def __init__
 
def __repr__
 
def __eq__
 
def __ne__
 
def __lt__
 
def __le__
 
def __gt__
 
def __ge__
 
def __neg__
 
def __pos__
 
def __get__
 
def __set__
 
def __delete__
 

Additional Inherited Members

- Static Public Attributes inherited from google.appengine.ext.ndb.model.Property
 IN = _IN
 

Detailed Description

A Property whose value is determined by a user-supplied function.

Computed properties cannot be set directly, but are instead generated by a
function when required. They are useful to provide fields in the datastore
that can be used for filtering or sorting without having to manually set the
value in code - for example, sorting on the length of a BlobProperty, or
using an equality filter to check if another field is not empty.

ComputedProperty can be declared as a regular property, passing a function as
the first argument, or it can be used as a decorator for the function that
does the calculation.

Example:

>>> class DatastoreFile(Model):
...   name = StringProperty()
...   name_lower = ComputedProperty(lambda self: self.name.lower())
...
...   data = BlobProperty()
...
...   @ComputedProperty
...   def size(self):
...     return len(self.data)
...
...   def _compute_hash(self):
...     return hashlib.sha1(self.data).hexdigest()
...   hash = ComputedProperty(_compute_hash, name='sha1')

Constructor & Destructor Documentation

def google.appengine.ext.ndb.model.ComputedProperty.__init__ (   self,
  func,
  name = None,
  indexed = None,
  repeated = None,
  verbose_name = None 
)
Constructor.

Args:
  func: A function that takes one argument, the model instance, and returns
    a calculated value.

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