View source on GitHub |
A property that represents a many-to-one reference to another model.
Inherits From: Property
, expected_type
google.appengine.ext.db.Reference(
reference_class=None, verbose_name=None, collection_name=None, **attrs
)
For example, a reference property in model A that refers to model B forms a many-to-one relationship from A to B: every instance of A refers to a single B instance, and every B instance can have many A instances refer to it.
Args | |
---|---|
reference_class
|
Which model class this property references. |
verbose_name
|
User friendly name of property. |
collection_name
|
If provided, alternate name of collection on
reference_class to store back references. Use this to allow a Model
to have multiple fields which refer to the same class.
|
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
)
Get key of reference rather than reference itself.
make_value_from_datastore
make_value_from_datastore(
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. |
make_value_from_datastore_index_value
make_value_from_datastore_index_value(
index_value
)
validate
validate(
value
)
Validate reference.
Returns | |
---|---|
A valid value. |
Raises | |
---|---|
BadValueError for the following reasons:
|
Class Variables | |
---|---|
creation_counter |
2
|