View source on GitHub |
A user property.
Inherits From: Property
, expected_type
google.appengine.ext.db.UserProperty(
verbose_name=None,
name=None,
required=False,
validator=None,
choices=None,
auto_current_user=False,
auto_current_user_add=False,
indexed=True
)
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.
|
required
|
Whether property is required. |
validator
|
User provided method used for validation. |
choices
|
User provided set of valid property values. |
auto_current_user
|
If true, the value is set to the current user each time the entity is written to the datastore. |
auto_current_user_add
|
If true, the value is set to the current user the first time the entity is written to the datastore. |
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 user.
Returns | |
---|---|
Value of users.get_current_user() if auto_current_user or
auto_current_user_add is set; else None . (But not the default
implementation, since we don't support the default keyword
argument.)
|
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
)
Get new value for property to send to datastore.
Returns | |
---|---|
Value of users.get_current_user() if auto_current_user is set;
else AUTO_UPDATE_UNCHANGED .
|
get_value_for_datastore
get_value_for_datastore(
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. |
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 user.
Returns | |
---|---|
A valid value. |
Raises | |
---|---|
BadValueError if property is not instance of 'User'.
|
Class Variables | |
---|---|
creation_counter |
2
|