当前位置: 首页>>代码示例>>Python>>正文


Python associationproxy.AssociationProxy方法代码示例

本文整理汇总了Python中sqlalchemy.ext.associationproxy.AssociationProxy方法的典型用法代码示例。如果您正苦于以下问题:Python associationproxy.AssociationProxy方法的具体用法?Python associationproxy.AssociationProxy怎么用?Python associationproxy.AssociationProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.ext.associationproxy的用法示例。


在下文中一共展示了associationproxy.AssociationProxy方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_field_type

# 需要导入模块: from sqlalchemy.ext import associationproxy [as 别名]
# 或者: from sqlalchemy.ext.associationproxy import AssociationProxy [as 别名]
def get_field_type(model, fieldname):
    """Helper which returns the SQLAlchemy type of the field.

    """
    field = getattr(model, fieldname)
    if isinstance(field, ColumnElement):
        fieldtype = field.type
    else:
        if isinstance(field, AssociationProxy):
            field = field.remote_attr
        if hasattr(field, 'property'):
            prop = field.property
            if isinstance(prop, RelProperty):
                return None
            fieldtype = prop.columns[0].type
        else:
            return None
    return fieldtype 
开发者ID:yfauser,项目名称:planespotter,代码行数:20,代码来源:helpers.py

示例2: is_like_list

# 需要导入模块: from sqlalchemy.ext import associationproxy [as 别名]
# 或者: from sqlalchemy.ext.associationproxy import AssociationProxy [as 别名]
def is_like_list(instance, relation):
    """Returns ``True`` if and only if the relation of `instance` whose name is
    `relation` is list-like.

    A relation may be like a list if, for example, it is a non-lazy one-to-many
    relation, or it is a dynamically loaded one-to-many.

    """
    if relation in instance._sa_class_manager:
        return instance._sa_class_manager[relation].property.uselist
    elif hasattr(instance, relation):
        attr = getattr(instance._sa_instance_state.class_, relation)
        if hasattr(attr, 'property'):
            return attr.property.uselist
    related_value = getattr(type(instance), relation, None)
    if isinstance(related_value, AssociationProxy):
        local_prop = related_value.local_attr.prop
        if isinstance(local_prop, RelProperty):
            return local_prop.uselist
    return False 
开发者ID:yfauser,项目名称:planespotter,代码行数:22,代码来源:helpers.py

示例3: maybe_convert_values

# 需要导入模块: from sqlalchemy.ext import associationproxy [as 别名]
# 或者: from sqlalchemy.ext.associationproxy import AssociationProxy [as 别名]
def maybe_convert_values(self, model_class, data):
        ret = data.copy()
        for col_name, value in data.items():
            col = getattr(model_class, col_name)
            if isinstance(col, AssociationProxy) or col.impl.uses_objects:
                ret[col_name] = self.convert_identifiers(value)
            elif not hasattr(col, 'type'):
                continue
            elif isinstance(col.type, Date):
                if value in ('today', 'now', 'utcnow'):
                    ret[col_name] = utcnow().date
                else:
                    ret[col_name] = parse_datetime(value).date
            elif isinstance(col.type, DateTime):
                if value in ('now', 'utcnow'):
                    ret[col_name] = utcnow()
                elif not isinstance(value, datetime.datetime):
                    ret[col_name] = parse_datetime(value)
        return ret 
开发者ID:briancappello,项目名称:flask-react-spa,代码行数:21,代码来源:_model_factory.py

示例4: is_column_array

# 需要导入模块: from sqlalchemy.ext import associationproxy [as 别名]
# 或者: from sqlalchemy.ext.associationproxy import AssociationProxy [as 别名]
def is_column_array(self, name: str) -> bool:
        # Well, even though this column is clearly an array, it does not behave like one when thought of in terms of
        # Postgres operators, because the underlying comparison is done to a scalar column.
        # Example: AssociationProxy to User.name will use the `name` column for comparisons, which is scalar!
        return False 
开发者ID:kolypto,项目名称:py-mongosql,代码行数:7,代码来源:bag.py

示例5: _get_model_association_proxies

# 需要导入模块: from sqlalchemy.ext import associationproxy [as 别名]
# 或者: from sqlalchemy.ext.associationproxy import AssociationProxy [as 别名]
def _get_model_association_proxies(model, ins):
    """ Get a dict of model association_proxy attributes """
    # Ignore AssociationProxy attrs for SA 1.2.x
    if SA_12:
        warnings.warn('MongoSQL only supports AssociationProxy columns with SqlAlchemy 1.3.x')
        return {}

    return {name: getattr(model, name)
            for name, c in ins.all_orm_descriptors.items()
            if not name.startswith('_')
            and isinstance(c, AssociationProxy)} 
开发者ID:kolypto,项目名称:py-mongosql,代码行数:13,代码来源:bag.py

示例6: related_query

# 需要导入模块: from sqlalchemy.ext import associationproxy [as 别名]
# 或者: from sqlalchemy.ext.associationproxy import AssociationProxy [as 别名]
def related_query(self, obj_id, relationship, full_object=True):
        """Construct query for related objects.

        Parameters:
            obj_id (str): id of an item in this view's collection.

            relationship: the relationship object to get related objects from.
                This can be a RelationshipProperty or AssociationProxy object.

            related_to (model class or None): the class the relationship is
                coming from. AssociationProxy relationships use this. It
                defaults to ``None``, which is interpreted as self.model.

            full_object (bool): if full_object is ``True``, query for all
                requested columns (probably to build resource objects). If
                full_object is False, only query for the key column (probably
                to build resource identifiers).

        Returns:
            sqlalchemy.orm.query.Query: query which will fetch related
            object(s).
        """
        if isinstance(relationship.obj, AssociationProxy):
            query = self.association_proxy_query(
                obj_id, relationship, full_object=full_object
            )
        else:
            query = self.standard_relationship_query(
                obj_id, relationship, full_object=full_object
            )
        return query 
开发者ID:colinhiggs,项目名称:pyramid-jsonapi,代码行数:33,代码来源:collection_view.py

示例7: get_related_model

# 需要导入模块: from sqlalchemy.ext import associationproxy [as 别名]
# 或者: from sqlalchemy.ext.associationproxy import AssociationProxy [as 别名]
def get_related_model(model, relationname):
    """Gets the class of the model to which `model` is related by the attribute
    whose name is `relationname`.

    """
    if hasattr(model, relationname):
        attr = getattr(model, relationname)
        if hasattr(attr, 'property') \
                and isinstance(attr.property, RelProperty):
            return attr.property.mapper.class_
        if isinstance(attr, AssociationProxy):
            return get_related_association_proxy_model(attr)
    return None 
开发者ID:yfauser,项目名称:planespotter,代码行数:15,代码来源:helpers.py

示例8: _iter_association_proxies

# 需要导入模块: from sqlalchemy.ext import associationproxy [as 别名]
# 或者: from sqlalchemy.ext.associationproxy import AssociationProxy [as 别名]
def _iter_association_proxies(cls):
        for col, value in vars(cls).items():
            if isinstance(value, associationproxy.AssociationProxy):
                yield col 
开发者ID:apache,项目名称:incubator-ariatosca,代码行数:6,代码来源:mixins.py

示例9: _sub_operator

# 需要导入模块: from sqlalchemy.ext import associationproxy [as 别名]
# 或者: from sqlalchemy.ext.associationproxy import AssociationProxy [as 别名]
def _sub_operator(model, argument, fieldname):
    """Recursively calls :func:`QueryBuilder._create_operation` when argument
    is a dictionary of the form specified in :ref:`search`.

    This function is for use with the ``has`` and ``any`` search operations.

    """
    if isinstance(model, InstrumentedAttribute):
        submodel = model.property.mapper.class_
    elif isinstance(model, AssociationProxy):
        submodel = get_related_association_proxy_model(model)
    else:  # TODO what to do here?
        pass
    if isinstance(argument, dict):
        fieldname = argument['name']
        operator = argument['op']
        argument = argument.get('val')
        relation = None
        if '__' in fieldname:
            fieldname, relation = fieldname.split('__')
        return QueryBuilder._create_operation(submodel, fieldname, operator,
                                              argument, relation)
    # Support legacy has/any with implicit eq operator
    return getattr(submodel, fieldname) == argument


#: The mapping from operator name (as accepted by the search method) to a
#: function which returns the SQLAlchemy expression corresponding to that
#: operator.
#:
#: Each of these functions accepts either one, two, or three arguments. The
#: first argument is the field object on which to apply the operator. The
#: second argument, where it exists, is either the second argument to the
#: operator or a dictionary as described below. The third argument, where it
#: exists, is the name of the field.
#:
#: For functions that accept three arguments, the second argument may be a
#: dictionary containing ``'name'``, ``'op'``, and ``'val'`` mappings so that
#: :func:`QueryBuilder._create_operation` may be applied recursively. For more
#: information and examples, see :ref:`search`.
#:
#: Some operations have multiple names. For example, the equality operation can
#: be described by the strings ``'=='``, ``'eq'``, ``'equals'``, etc. 
开发者ID:yfauser,项目名称:planespotter,代码行数:45,代码来源:search.py


注:本文中的sqlalchemy.ext.associationproxy.AssociationProxy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。