django_sorcery.db.composites module

Support for reusable sqlalchemy composite fields.

class django_sorcery.db.composites.BaseComposite(*args, **kwargs)[source]

Bases: object

Base class for creating composite classes which CompositeField will understand.

For example:

class MyComposite(object):
    foo = db.Column(db.Integer())
    bar = db.Column(db.Integer())

class MyModel(db.Model):
    test = db.CompositeField(MyComposite)
    # both test_foo and test_bar columns will be added to model
    # their instrumented properties will be _test_foo and _test_bar
as_dict()[source]

Serializer composite to a dictionary.

class django_sorcery.db.composites.CompositeField(class_, **kwargs)[source]

Bases: sqlalchemy.orm.descriptor_props.CompositeProperty

Composite field which understands composite objects with builtin columns.

See BaseComposite for examples.

instrument_class(mapper)[source]

Hook called by the Mapper to the property to initiate instrumentation of the class attribute managed by this MapperProperty.

The MapperProperty here will typically call out to the attributes module to set up an InstrumentedAttribute.

This step is the first of two steps to set up an InstrumentedAttribute, and is called early in the mapper setup process.

The second step is typically the init_class_attribute step, called from StrategizedProperty via the post_instrument_class() hook. This step assigns additional state to the InstrumentedAttribute (specifically the “impl”) which has been determined after the MapperProperty has determined what kind of persistence management it needs to do (e.g. scalar, object, collection, etc).