Entity properties¶
Entities are a collection of Properties of different types. These classes implement the default set of types used in endpoints.
At entity class level, these properties are used in querying entities:
>>> import datetime
>>> Order.ShippedDate > datetime.datetime.now()
'ShippedDate gt 2016-02-19T12:02:04.956226'
>>> Service.query(Order).filter(Order.OrderID == 1234)
Once the entity is instanced, the properties act as data getters and setters:
>>> order = Order()
>>> order.ShippedDate = datetime.datetime.now()
>>> Service.save(order)
Setting a new value to a property marks the property as dirty, and will be
sent to the endpoint when save()
is
called.
This behavior is similar to SQLAlchemy’s ORM.
Creating new property types¶
All properties must subclass PropertyBase
, and implement the
serialization methods. You can then use the created Property class in your
custom defined entities. Replacing the default types is not supported.
-
class
odata.property.
PropertyBase
(name, primary_key=False, is_collection=False, is_computed_value=False)¶ A base class for all properties.
Parameters: - name – Name of the property in the endpoint
- primary_key – This property is a primary key
- is_collection – This property contains multiple values
-
deserialize
(value)¶ Called when deserializing the value from JSON to Python. Implement this method when creating a new Property class
Parameters: value – Value received in JSON Returns: Value that will be passed to Python
-
escape_value
(value)¶ Called when escaping the property value for usage in Query string. Implement this method when creating a new Property class
Parameters: value – Value of this property Returns: Escaped value that can be used in Query string
-
serialize
(value)¶ Called when serializing the value to JSON. Implement this method when creating a new Property class
Parameters: value – Value given in Python code Returns: Value that will be used in JSON
Types¶
-
class
odata.property.
BooleanProperty
(name, primary_key=False, is_collection=False, is_computed_value=False)¶ Property that stores a boolean value
-
class
odata.property.
DatetimeProperty
(name, primary_key=False, is_collection=False, is_computed_value=False)¶ Property that stores a datetime object. JSON does not support date objects natively so dates are transmitted as ISO-8601 formatted strings
-
class
odata.property.
DecimalProperty
(name, primary_key=False, is_collection=False, is_computed_value=False)¶ Property that stores a decimal value. JSON does not support this directly, so the value will be transmitted as a float
-
class
odata.property.
FloatProperty
(name, primary_key=False, is_collection=False, is_computed_value=False)¶ Property that stores a float value
-
class
odata.property.
IntegerProperty
(name, primary_key=False, is_collection=False, is_computed_value=False)¶ Property that stores a plain old integer
-
class
odata.property.
StringProperty
(name, primary_key=False, is_collection=False, is_computed_value=False)¶ Property that stores a unicode string
-
class
odata.property.
UUIDProperty
(name, primary_key=False, is_collection=False, is_computed_value=False)¶ Property that stores a UUID (also known as GUID) value. JSON does not support this directly, so the value will be transmitted as a string. Unlike
StringProperty
, it does not escape quotes as query filters do not use quotes for UUID