google.appengine.ext.blobstore.BlobReferenceProperty

Property compatible with db.Model classes.

Inherits From: Property, expected_type

Add references to blobs to domain models using BlobReferenceProperty::

class Picture(db.Model):
  title = db.StringProperty()
  image = blobstore.BlobReferenceProperty()
  thumbnail = blobstore.BlobReferenceProperty()

To find the size of a picture using this model::

picture = Picture.get(picture_key)
print picture.image.size

BlobInfo objects are lazily loaded, so iterating over models for BlobKeys is efficient. The following sample code does not need to hit Datastore for each image key::

list_of_untitled_blobs = []
for picture in Picture.gql("WHERE title=''"):
  list_of_untitled_blobs.append(picture.image.key())

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.

Child Classes

class data_type

Methods

datastore_type

View source

Deprecated backwards-compatible accessor method for self.data_type.

default_value

View source

Default value for unassigned values.

Returns
Default value as provided by __init__(default).

empty

View source

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.

get_updated_value_for_datastore

View source

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.

get_value_for_datastore

View source

Returns a model property translated to a datastore value.

Args
model_instance The model property that you want to translate.

Returns
The model property that was translated from datastore.

make_value_from_datastore

View source

Returns a datastore value to BlobInfo.

Args
value The datastore value that you want to translate.

Returns
A BlobInfo that was translated from datastore.

make_value_from_datastore_index_value

View source

validate

View source

Validates that an assigned value is BlobInfo.

This method automatically converts from strings and BlobKey instances.

Args
value The value that you want to validate.

Returns
Information about whether an assigned value is BlobInfo.

creation_counter 2