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