stalker.models.mixins.TargetEntityTypeMixin

Inheritance diagram of stalker.models.mixins.TargetEntityTypeMixin
class stalker.models.mixins.TargetEntityTypeMixin(target_entity_type=None, **kwargs)[source]

Bases: object

Adds target_entity_type attribute to mixed in class.

Parameters:target_entity_type

The target entity type which this class is designed for. Should be a class or a class name.

For example:

from stalker import SimpleEntity, TargetEntityTypeMixin, Project

class A(SimpleEntity, TargetEntityTypeMixin):
    __tablename__ = “As”
    __mapper_args__ = {“polymorphic_identity”: “A”}

    def __init__(self, **kwargs):
        super(A, self).__init__(**kwargs)
        TargetEntityTypeMixin.__init__(self, **kwargs)

a_obj = A(target_entity_type=Project)

The a_obj will only be accepted by Project instances. You can not assign it to any other class which accepts a Type instance.

To control the mixed-in class behaviour add these class variables to the mixed in class:

__nullable_target__ : controls if the target_entity_type can be
nullable or not. Default is False.
__unique_target__ : controls if the target_entity_type should be
unique, so there is only one object for one type. Default is False.
__init__(target_entity_type=None, **kwargs)[source]

Methods

__init__([target_entity_type])

Attributes

target_entity_type