class hybrid_property(interfaces.InspectionAttrInfo, ORMDescriptor[
Known subclasses: sqlalchemy.ext.indexable.index_property
A decorator which allows definition of a Python descriptor with both instance-level and class-level behavior.
Method | __delete__ |
Undocumented |
Method | __get__ |
Undocumented |
Method | __init__ |
Create a new :class:`.hybrid_property`. |
Method | __set__ |
Undocumented |
Method | comparator |
Provide a modifying decorator that defines a custom comparator producing method. |
Method | deleter |
Provide a modifying decorator that defines a deletion method. |
Method | expression |
Provide a modifying decorator that defines a SQL-expression producing method. |
Method | getter |
Provide a modifying decorator that defines a getter method. |
Method | setter |
Provide a modifying decorator that defines a setter method. |
Method | update |
Provide a modifying decorator that defines an UPDATE tuple producing method. |
Class Variable | __name__ |
Undocumented |
Class Variable | is |
True if this object is a Python :term:`descriptor`. |
Instance Variable | custom |
Undocumented |
Instance Variable | expr |
Undocumented |
Instance Variable | fdel |
Undocumented |
Instance Variable | fget |
Undocumented |
Instance Variable | fset |
Undocumented |
Instance Variable | update |
Undocumented |
Property | inplace |
Return the inplace mutator for this :class:`.hybrid_property`. |
Property | overrides |
Prefix for a method that is overriding an existing attribute. |
Class | _ |
A builder helper for .hybrid_property. |
Method | _copy |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Property | _expr |
Undocumented |
Inherited from InspectionAttrInfo
:
Class Variable | __slots__ |
Undocumented |
Property | info |
Info dictionary associated with the object, allowing user-defined data to be associated with this :class:`.InspectionAttr`. |
Inherited from InspectionAttr
(via InspectionAttrInfo
):
Class Variable | is |
True if this object is an instance of :class:`.AliasedClass`. |
Class Variable | is |
True if this object is an instance of :class:`.Bundle`. |
Class Variable | is |
True if this object is an instance of :class:`_expression.ClauseElement`. |
Class Variable | is |
True if this object is an instance of :class:`.InstanceState`. |
Class Variable | is |
True if this object is an instance of :class:`_orm.Mapper`. |
Class Variable | is |
True if this object is an instance of :class:`.MapperProperty`. |
Class Variable | is |
Return True if this object is an instance of :class:`_expression.Selectable`. |
Class Variable | _is |
True if this object is an internal proxy object. |
_HybridGetterType[ _T]
, fset: Optional[ _HybridSetterType[ _T]]
= None, fdel: Optional[ _HybridDeleterType[ _T]]
= None, expr: Optional[ _HybridExprCallableType[ _T]]
= None, custom_comparator: Optional[ Comparator[ _T]]
= None, update_expr: Optional[ _HybridUpdaterType[ _T]]
= None):
(source)
¶
sqlalchemy.ext.indexable.index_property
Create a new :class:`.hybrid_property`. Usage is typically via decorator:: from sqlalchemy.ext.hybrid import hybrid_property class SomeClass: @hybrid_property def value(self): return self._value @value.setter def value(self, value): self._value = value
_HybridComparatorCallableType[ _T]
) -> hybrid_property[ _T]
:
(source)
¶
Provide a modifying decorator that defines a custom comparator producing method. The return value of the decorated method should be an instance of :class:`~.hybrid.Comparator`. .. note:: The :meth:`.hybrid_property.comparator` decorator **replaces** the use of the :meth:`.hybrid_property.expression` decorator. They cannot be used together. When a hybrid is invoked at the class level, the :class:`~.hybrid.Comparator` object given here is wrapped inside of a specialized :class:`.QueryableAttribute`, which is the same kind of object used by the ORM to represent other mapped attributes. The reason for this is so that other class-level attributes such as docstrings and a reference to the hybrid itself may be maintained within the structure that's returned, without any modifications to the original comparator object passed in. .. note:: When referring to a hybrid property from an owning class (e.g. ``SomeClass.some_hybrid``), an instance of :class:`.QueryableAttribute` is returned, representing the expression or comparator object as this hybrid object. However, that object itself has accessors called ``expression`` and ``comparator``; so when attempting to override these decorators on a subclass, it may be necessary to qualify it using the :attr:`.hybrid_property.overrides` modifier first. See that modifier for details.
Provide a modifying decorator that defines a SQL-expression producing method. When a hybrid is invoked at the class level, the SQL expression given here is wrapped inside of a specialized :class:`.QueryableAttribute`, which is the same kind of object used by the ORM to represent other mapped attributes. The reason for this is so that other class-level attributes such as docstrings and a reference to the hybrid itself may be maintained within the structure that's returned, without any modifications to the original SQL expression passed in. .. note:: When referring to a hybrid property from an owning class (e.g. ``SomeClass.some_hybrid``), an instance of :class:`.QueryableAttribute` is returned, representing the expression or comparator object as well as this hybrid object. However, that object itself has accessors called ``expression`` and ``comparator``; so when attempting to override these decorators on a subclass, it may be necessary to qualify it using the :attr:`.hybrid_property.overrides` modifier first. See that modifier for details. .. seealso:: :ref:`hybrid_distinct_expression`
Provide a modifying decorator that defines an UPDATE tuple producing method. The method accepts a single value, which is the value to be rendered into the SET clause of an UPDATE statement. The method should then process this value into individual column expressions that fit into the ultimate SET clause, and return them as a sequence of 2-tuples. Each tuple contains a column expression as the key and a value to be rendered. E.g.:: class Person(Base): # ... first_name = Column(String) last_name = Column(String) @hybrid_property def fullname(self): return first_name + " " + last_name @fullname.update_expression def fullname(cls, value): fname, lname = value.split(" ", 1) return [ (cls.first_name, fname), (cls.last_name, lname) ] .. versionadded:: 1.2
True if this object is a Python :term:`descriptor`. This can refer to one of many types. Usually a :class:`.QueryableAttribute` which handles attributes events on behalf of a :class:`.MapperProperty`. But can also be an extension type such as :class:`.AssociationProxy` or :class:`.hybrid_property`. The :attr:`.InspectionAttr.extension_type` will refer to a constant identifying the specific subtype. .. seealso:: :attr:`_orm.Mapper.all_orm_descriptors`
Return the inplace mutator for this :class:`.hybrid_property`. This is to allow in-place mutation of the hybrid, allowing the first hybrid method of a certain name to be re-used in order to add more methods without having to name those methods the same, e.g.:: class Interval(Base): # ... @hybrid_property def radius(self) -> float: return abs(self.length) / 2 @radius.inplace.setter def _radius_setter(self, value: float) -> None: self.length = value * 2 @radius.inplace.expression def _radius_expression(cls) -> ColumnElement[float]: return type_coerce(func.abs(cls.length) / 2, Float) .. versionadded:: 2.0.4 .. seealso:: :ref:`hybrid_pep484_naming`
Prefix for a method that is overriding an existing attribute. The :attr:`.hybrid_property.overrides` accessor just returns this hybrid object, which when called at the class level from a parent class, will de-reference the "instrumented attribute" normally returned at this level, and allow modifying decorators like :meth:`.hybrid_property.expression` and :meth:`.hybrid_property.comparator` to be used without conflicting with the same-named attributes normally present on the :class:`.QueryableAttribute`:: class SuperClass: # ... @hybrid_property def foobar(self): return self._foobar class SubClass(SuperClass): # ... @SuperClass.foobar.overrides.expression def foobar(cls): return func.subfoobar(self._foobar) .. versionadded:: 1.2 .. seealso:: :ref:`hybrid_reuse_subclass`
Any
) -> Callable[ [ Any], _HybridClassLevelAccessor[ _T]]
:
(source)
¶
Undocumented
_HybridExprCallableType[ _T]
) -> Callable[ [ Any], _HybridClassLevelAccessor[ _T]]
:
(source)
¶
Undocumented