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


Python orm.relationship方法代码示例

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


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

示例1: _memoized_attr_info

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def _memoized_attr_info(self):
        """Info dictionary associated with the object, allowing user-defined
        data to be associated with this :class:`.InspectionAttr`.

        The dictionary is generated when first accessed.  Alternatively,
        it can be specified as a constructor argument to the
        :func:`.column_property`, :func:`.relationship`, or :func:`.composite`
        functions.

        .. versionadded:: 0.8  Added support for .info to all
           :class:`.MapperProperty` subclasses.

        .. versionchanged:: 1.0.0 :attr:`.MapperProperty.info` is also
           available on extension types via the
           :attr:`.InspectionAttrInfo.info` attribute, so that it can apply
           to a wider variety of ORM and extension constructs.

        .. seealso::

            :attr:`.QueryableAttribute.info`

            :attr:`.SchemaItem.info`

        """
        return {} 
开发者ID:jpush,项目名称:jbox,代码行数:27,代码来源:interfaces.py

示例2: annotation_association

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def annotation_association(cls):
        name = cls.__name__
        discriminator = name.lower()

        assoc_cls = type(
            "%sAnnotationAssociation" % name, (AnnotationAssociation,),
            dict(
                __tablename__ = None,
                __mapper_args__ = {"polymorphic_identity": discriminator},
            ),
        )

        cls.annotation = association_proxy(
            "annotation_association",
            "annotation",
            creator = lambda annotation: assoc_cls(annotation = annotation),
        )
        return relationship(
            assoc_cls, backref = backref("parent", uselist = False, collection_class = ordering_list('position'))
        ) 
开发者ID:christoph2,项目名称:pyA2L,代码行数:22,代码来源:__init__.py

示例3: ReferenceCol

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def ReferenceCol(tablename, nullable=False, pk_name='id', **kwargs):
    """Column that adds primary key foreign key reference.

    Usage: ::

        category_id = ReferenceCol('category')
        category = relationship('Category', backref='categories')
    """
    return db.Column(
        db.ForeignKey("{0}.{1}".format(tablename, pk_name)),
        nullable=nullable, **kwargs) 
开发者ID:codeforamerica,项目名称:comport,代码行数:13,代码来源:database.py

示例4: __init__

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def __init__(self, private_key=None, wei_target_balance=None, wei_topup_threshold=None):

        if private_key:
            self.private_key = private_key
        else:
            self.private_key = Web3.toHex(keccak(os.urandom(4096)))

        self.wei_target_balance = wei_target_balance
        self.wei_topup_threshold = wei_topup_threshold

# https://stackoverflow.com/questions/20830118/creating-a-self-referencing-m2m-relationship-in-sqlalchemy-flask 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:13,代码来源:models.py

示例5: to_json

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def to_json(self):
        """Exports the object to a JSON friendly dict

        Returns:
             Dict representation of object type
        """
        output = {
            '__type': self.__class__.__name__
        }

        cls_attribs = self.__class__.__dict__
        for attrName in cls_attribs:
            attr = getattr(self.__class__, attrName)
            value = getattr(self, attrName)
            value_class = type(value)

            if issubclass(type(attr), QueryableAttribute):
                # List of Model, BaseModelMixin objects (one-to-many relationship)
                if issubclass(value_class, InstrumentedList):
                    output[to_camelcase(attrName)] = [x.to_json() for x in value]

                # Model, BaseModelMixin object (one-to-one relationship)
                elif issubclass(value_class, Model):
                    output[to_camelcase(attrName)] = value.to_json()

                # Datetime object
                elif isinstance(value, datetime):
                    output[to_camelcase(attrName)] = isoformat(value)

                elif isinstance(value, enum.Enum):
                    output[to_camelcase(attrName)] = value.name

                # Any primitive type
                else:
                    output[to_camelcase(attrName)] = value

        return output 
开发者ID:RiotGames,项目名称:cloud-inquisitor,代码行数:39,代码来源:base.py

示例6: cuser

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def cuser(cls):
        return relationship('User', remote_side=User.id,
                            foreign_keys='{}.cuid'.format(cls.__name__), doc="Created by") 
开发者ID:kolypto,项目名称:py-mongosql,代码行数:5,代码来源:models.py

示例7: roles

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def roles(cls):
        return FsModels.db.relationship(
            "Role",
            secondary=FsModels.roles_users,
            backref=FsModels.db.backref("users", lazy="dynamic"),
        ) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:8,代码来源:fsqla.py

示例8: user

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def user(cls):
        return relationship("User") 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:4,代码来源:fsqla.py

示例9: client_id

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def client_id(cls):
        return Column(
            Integer, ForeignKey("oauth2_client.id", ondelete="CASCADE"), nullable=False
        )

    # client = relationship("fs_oauth2_client") 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:8,代码来源:fsqla.py

示例10: transformations

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def transformations(self, relationship="all"):
        """Get all the transformations of this info.

        Return a list of transformations involving this info. ``relationship``
        can be "parent" (in which case only transformations where the info is
        the ``info_in`` are returned), "child" (in which case only
        transformations where the info is the ``info_out`` are returned) or
        ``all`` (in which case any transformations where the info is the
        ``info_out`` or the ``info_in`` are returned). The default is ``all``

        """
        if relationship not in ["all", "parent", "child"]:
            raise ValueError(
                "You cannot get transformations of relationship {}".format(relationship)
                + "Relationship can only be parent, child or all."
            )

        if relationship == "all":
            return Transformation.query.filter(
                and_(
                    Transformation.failed == false(),
                    or_(
                        Transformation.info_in == self, Transformation.info_out == self
                    ),
                )
            ).all()

        if relationship == "parent":
            return Transformation.query.filter_by(
                info_in_id=self.id, failed=False
            ).all()

        if relationship == "child":
            return Transformation.query.filter_by(
                info_out_id=self.id, failed=False
            ).all() 
开发者ID:Dallinger,项目名称:Dallinger,代码行数:38,代码来源:models.py

示例11: actual_amount

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def actual_amount(cls):
        # see: http://docs.sqlalchemy.org/en/latest/orm/extensions/hybrid.html
        # #correlated-subquery-relationship-hybrid
        return select(
            [func.sum(BudgetTransaction.amount)]
        ).where(
            BudgetTransaction.trans_id.__eq__(cls.id)
        ).label('actual_amount') 
开发者ID:jantman,项目名称:biweeklybudget,代码行数:10,代码来源:transaction.py

示例12: reference_col

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def reference_col(tablename, nullable=False, pk_name='id', **kwargs):
    """Column that adds primary key foreign key reference.

    Usage: ::

        category_id = reference_col('category')
        category = relationship('Category', backref='categories')
    """
    return db.Column(
        db.ForeignKey('{0}.{1}'.format(tablename, pk_name)),
        nullable=nullable, **kwargs) 
开发者ID:gothinkster,项目名称:flask-realworld-example-app,代码行数:13,代码来源:database.py

示例13: test_onetomany

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def test_onetomany(metadata):
    Table(
        "simple_items",
        metadata,
        Column("id", INTEGER, primary_key=True),
        Column("container_id", INTEGER),
        ForeignKeyConstraint(["container_id"], ["simple_containers.id"]),
    )
    Table("simple_containers", metadata, Column("id", INTEGER, primary_key=True))

    assert (
        generate_code(metadata)
        == """\
# coding: utf-8
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
metadata = Base.metadata


class SimpleContainer(Base):
    __tablename__ = 'simple_containers'

    id = Column(Integer, primary_key=True)


class SimpleItem(Base):
    __tablename__ = 'simple_items'

    id = Column(Integer, primary_key=True)
    container_id = Column(ForeignKey('simple_containers.id'))

    container = relationship('SimpleContainer')
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:39,代码来源:test_codegen.py

示例14: test_onetomany_selfref

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def test_onetomany_selfref(metadata):
    Table(
        "simple_items",
        metadata,
        Column("id", INTEGER, primary_key=True),
        Column("parent_item_id", INTEGER),
        ForeignKeyConstraint(["parent_item_id"], ["simple_items.id"]),
    )

    assert (
        generate_code(metadata)
        == """\
# coding: utf-8
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
metadata = Base.metadata


class SimpleItem(Base):
    __tablename__ = 'simple_items'

    id = Column(Integer, primary_key=True)
    parent_item_id = Column(ForeignKey('simple_items.id'))

    parent_item = relationship('SimpleItem', remote_side=[id])
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:32,代码来源:test_codegen.py

示例15: test_onetomany_selfref_multi

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import relationship [as 别名]
def test_onetomany_selfref_multi(metadata):
    Table(
        "simple_items",
        metadata,
        Column("id", INTEGER, primary_key=True),
        Column("parent_item_id", INTEGER),
        Column("top_item_id", INTEGER),
        ForeignKeyConstraint(["parent_item_id"], ["simple_items.id"]),
        ForeignKeyConstraint(["top_item_id"], ["simple_items.id"]),
    )

    assert (
        generate_code(metadata)
        == """\
# coding: utf-8
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
metadata = Base.metadata


class SimpleItem(Base):
    __tablename__ = 'simple_items'

    id = Column(Integer, primary_key=True)
    parent_item_id = Column(ForeignKey('simple_items.id'))
    top_item_id = Column(ForeignKey('simple_items.id'))

    parent_item = relationship('SimpleItem', remote_side=[id], \
primaryjoin='SimpleItem.parent_item_id == SimpleItem.id')
    top_item = relationship('SimpleItem', remote_side=[id], \
primaryjoin='SimpleItem.top_item_id == SimpleItem.id')
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:38,代码来源:test_codegen.py


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