當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。