View source on GitHub
|
Property compatible with db.Model classes.
Inherits From: Property, expected_type
google.appengine.ext.blobstore.BlobReferenceProperty(
verbose_name=None,
name=None,
default=None,
required=False,
validator=None,
choices=None,
indexed=True
)
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())
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. |
Child Classes
Methods
datastore_type
datastore_type()
Deprecated backwards-compatible accessor method for self.data_type.
default_value
default_value()
Default value for unassigned values.
| Returns | |
|---|---|
Default value as provided by __init__(default).
|
empty
empty(
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.
|
get_updated_value_for_datastore
get_updated_value_for_datastore(
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.
|
get_value_for_datastore
get_value_for_datastore(
model_instance
)
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
make_value_from_datastore(
value
)
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
make_value_from_datastore_index_value(
index_value
)
validate
validate(
value
)
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.
|
Class Variables | |
|---|---|
| creation_counter |
2
|
View source on GitHub