![]() |
App Engine Python SDK
v1.6.9 rev.445
The Python runtime is available as an experimental Preview feature.
|
Public Member Functions | |
def | __init__ |
def | __property_config__ |
def | __get__ |
def | __set__ |
def | default_value |
def | validate |
def | empty |
def | get_value_for_datastore |
def | get_updated_value_for_datastore |
def | make_value_from_datastore_index_value |
def | make_value_from_datastore |
def | datastore_type |
Public Attributes | |
verbose_name | |
name | |
default | |
required | |
validator | |
choices | |
indexed | |
creation_counter | |
model_class | |
Static Public Attributes | |
int | creation_counter = 0 |
data_type = str | |
A Property is an attribute of a Model. It defines the type of the attribute, which determines how it is stored in the datastore and how the property values are validated. Different property types support different options, which change validation rules, default values, etc. The simplest example of a property is a StringProperty: class Story(db.Model): title = db.StringProperty()
def google.appengine.ext.db.Property.__init__ | ( | self, | |
verbose_name = None , |
|||
name = None , |
|||
default = None , |
|||
required = False , |
|||
validator = None , |
|||
choices = None , |
|||
indexed = True |
|||
) |
Initializes this Property with the given options. Args: verbose_name: User friendly name of property. name: Storage name for property. By default, uses attribute name as it is assigned in the Model sub-class. default: Default value for property if none is assigned. required: Whether property is required. validator: User provided method used for validation. choices: User provided set of valid property values. indexed: Whether property is indexed.
def google.appengine.ext.db.Property.__get__ | ( | self, | |
model_instance, | |||
model_class | |||
) |
Returns the value for this property on the given model instance. See http://docs.python.org/ref/descriptors.html for a description of the arguments to this class and what they mean.
def google.appengine.ext.db.Property.__property_config__ | ( | self, | |
model_class, | |||
property_name | |||
) |
Configure property, connecting it to its model. Configure the property so that it knows its property name and what class it belongs to. Args: model_class: Model class which Property will belong to. property_name: Name of property within Model instance to store property values in. By default this will be the property name preceded by an underscore, but may change for different subclasses.
def google.appengine.ext.db.Property.__set__ | ( | self, | |
model_instance, | |||
value | |||
) |
Sets the value for this property on the given model instance. See http://docs.python.org/ref/descriptors.html for a description of the arguments to this class and what they mean.
def google.appengine.ext.db.Property.datastore_type | ( | self | ) |
Deprecated backwards-compatible accessor method for self.data_type.
def google.appengine.ext.db.Property.default_value | ( | self | ) |
Default value for unassigned values. Returns: Default value as provided by __init__(default).
def google.appengine.ext.db.Property.empty | ( | self, | |
value | |||
) |
Determine if value is empty in the context of this property. For most kinds, this is equivalent to "not value", but for kinds like bool, the test is more subtle, so subclasses can override this method if necessary. Args: value: Value to validate against this Property. Returns: True if this value is considered empty in the context of this Property type, otherwise False.
def google.appengine.ext.db.Property.get_updated_value_for_datastore | ( | self, | |
model_instance | |||
) |
Determine new value for auto-updated property. Some properies (e.g. DateTimeProperty, UserProperty) optionally update their value on every put(). This call must return the new desired value for such properties. For all other properties, this call must return AUTO_UPDATE_UNCHANGED. Args: model_instance: Instance to get new value for. Returns: Datastore representation of the new model value in a form that is appropriate for storing in the datastore, or AUTO_UPDATE_UNCHANGED.
def google.appengine.ext.db.Property.get_value_for_datastore | ( | self, | |
model_instance | |||
) |
Datastore representation of this property. Looks for this property in the given model instance, and returns the proper datastore representation of the value that can be stored in a datastore entity. Most critically, it will fetch the datastore key value for reference properties. Some properies (e.g. DateTimeProperty, UserProperty) optionally update their value on every put(). This call must return the current value for such properties (get_updated_value_for_datastore returns the new value). Args: model_instance: Instance to fetch datastore value from. Returns: Datastore representation of the model value in a form that is appropriate for storing in the datastore.
def google.appengine.ext.db.Property.make_value_from_datastore | ( | self, | |
value | |||
) |
Native representation of this property. Given a value retrieved from a datastore entity, return a value, possibly converted, to be stored on the model instance. Usually this returns the value unchanged, but a property class may override this when it uses a different datatype on the model instance than on the entity. This API is not quite symmetric with get_value_for_datastore(), because the model instance on which to store the converted value may not exist yet -- we may be collecting values to be passed to a model constructor. Args: value: value retrieved from the datastore entity. Returns: The value converted for use as a model instance attribute.
def google.appengine.ext.db.Property.validate | ( | self, | |
value | |||
) |
Assert that provided value is compatible with this property. Args: value: Value to validate against this Property. Returns: A valid value, either the input unchanged or adapted to the required type. Raises: BadValueError if the value is not appropriate for this property in any way.