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

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

示例1: _memoized_attr_info

​点赞 6

# 需要导入模块: 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,

示例2: annotation_association

​点赞 6

# 需要导入模块: 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,

示例3: ReferenceCol

​点赞 5

# 需要导入模块: 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,

示例4: __init__

​点赞 5

# 需要导入模块: 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,

示例5: to_json

​点赞 5

# 需要导入模块: 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,

示例6: cuser

​点赞 5

# 需要导入模块: 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,

示例7: roles

​点赞 5

# 需要导入模块: 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,

示例8: user

​点赞 5

# 需要导入模块: from sqlalchemy import orm [as 别名]

# 或者: from sqlalchemy.orm import relationship [as 别名]

def user(cls):

return relationship("User")

开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:4,

示例9: client_id

​点赞 5

# 需要导入模块: 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,

示例10: transformations

​点赞 5

# 需要导入模块: 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,

示例11: actual_amount

​点赞 5

# 需要导入模块: 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,

示例12: reference_col

​点赞 5

# 需要导入模块: 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,

示例13: test_onetomany

​点赞 5

# 需要导入模块: 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,

示例14: test_onetomany_selfref

​点赞 5

# 需要导入模块: 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,

示例15: test_onetomany_selfref_multi

​点赞 5

# 需要导入模块: 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,

示例16: test_onetomany_noinflect

​点赞 5

# 需要导入模块: from sqlalchemy import orm [as 别名]

# 或者: from sqlalchemy.orm import relationship [as 别名]

def test_onetomany_noinflect(metadata):

Table(

"oglkrogk",

metadata,

Column("id", INTEGER, primary_key=True),

Column("fehwiuhfiwID", INTEGER),

ForeignKeyConstraint(["fehwiuhfiwID"], ["fehwiuhfiw.id"]),

)

Table("fehwiuhfiw", 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 Fehwiuhfiw(Base):

__tablename__ = 'fehwiuhfiw'

id = Column(Integer, primary_key=True)

class Oglkrogk(Base):

__tablename__ = 'oglkrogk'

id = Column(Integer, primary_key=True)

fehwiuhfiwID = Column(ForeignKey('fehwiuhfiw.id'))

fehwiuhfiw = relationship('Fehwiuhfiw')

"""

)

开发者ID:thomaxxl,项目名称:safrs,代码行数:39,

示例17: test_foreign_key_schema

​点赞 5

# 需要导入模块: from sqlalchemy import orm [as 别名]

# 或者: from sqlalchemy.orm import relationship [as 别名]

def test_foreign_key_schema(metadata):

Table(

"simple_items",

metadata,

Column("id", INTEGER, primary_key=True),

Column("other_item_id", INTEGER),

ForeignKeyConstraint(["other_item_id"], ["otherschema.other_items.id"]),

)

Table("other_items", metadata, Column("id", INTEGER, primary_key=True), schema="otherschema")

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 OtherItem(Base):

__tablename__ = 'other_items'

__table_args__ = {'schema': 'otherschema'}

id = Column(Integer, primary_key=True)

class SimpleItem(Base):

__tablename__ = 'simple_items'

id = Column(Integer, primary_key=True)

other_item_id = Column(ForeignKey('otherschema.other_items.id'))

other_item = relationship('OtherItem')

"""

)

开发者ID:thomaxxl,项目名称:safrs,代码行数:40,

示例18: parent

​点赞 5

# 需要导入模块: from sqlalchemy import orm [as 别名]

# 或者: from sqlalchemy.orm import relationship [as 别名]

def parent(self):

return relationship(

self,

order_by=lambda: self.left,

foreign_keys=[self.parent_id],

remote_side="{}.{}".format(self.__name__, self.get_pk_name()),

backref=backref(

"children",

cascade="all,delete",

order_by=lambda: (self.tree_id, self.left),

),

)

开发者ID:uralbash,项目名称:sqlalchemy_mptt,代码行数:14,

示例19: reference_col

​点赞 5

# 需要导入模块: from sqlalchemy import orm [as 别名]

# 或者: from sqlalchemy.orm import relationship [as 别名]

def reference_col(tablename: str, nullable: bool = False, pk_name: str = 'id',

onupdate: str = None, ondelete: str = None, **kwargs: Any) \

-> Column:

"""Column that adds primary key foreign key reference.

Args:

tablename (str): Model.__table_name__.

nullable (bool): Default is False.

pk_name (str): Primary column's name.

onupdate (str): If Set, emit ON UPDATE when

issuing DDL for this constraint. Typical values include CASCADE,

DELETE and RESTRICT.

ondelete (str): If set, emit ON DELETE when

issuing DDL for this constraint. Typical values include CASCADE,

DELETE and RESTRICT.

Others:

See ``sqlalchemy.Column``.

Examples::

from sqlalchemy.orm import relationship

role_id = reference_col('role')

role = relationship('Role', backref='users', cascade='all, delete')

"""

return Column(

ForeignKey('{0}.{1}'.format(tablename, pk_name),

onupdate=onupdate, ondelete=ondelete),

nullable=nullable, **kwargs)

开发者ID:TTWShell,项目名称:hobbit-core,代码行数:34,代码来源:db.py

示例20: home_team

​点赞 5

# 需要导入模块: from sqlalchemy import orm [as 别名]

# 或者: from sqlalchemy.orm import relationship [as 别名]

def home_team(cls):

return relationship('Clubs', foreign_keys="{}.home_team_id".format(cls.__name__),

backref=backref('home_friendly_matches'))

开发者ID:soccermetrics,项目名称:marcotti,代码行数:5,

示例21: away_team

​点赞 5

# 需要导入模块: from sqlalchemy import orm [as 别名]

# 或者: from sqlalchemy.orm import relationship [as 别名]

def away_team(cls):

return relationship('Clubs', foreign_keys="{}.away_team_id".format(cls.__name__),

backref=backref('away_friendly_matches'))

开发者ID:soccermetrics,项目名称:marcotti,代码行数:5,

示例22: home_team

​点赞 5

# 需要导入模块: from sqlalchemy import orm [as 别名]

# 或者: from sqlalchemy.orm import relationship [as 别名]

def home_team(cls):

return relationship('Countries', foreign_keys="{}.home_team_id".format(cls.__name__),

backref=backref('home_friendly_matches'))

开发者ID:soccermetrics,项目名称:marcotti,代码行数:5,

示例23: away_team

​点赞 5

# 需要导入模块: from sqlalchemy import orm [as 别名]

# 或者: from sqlalchemy.orm import relationship [as 别名]

def away_team(cls):

return relationship('Countries', foreign_keys="{}.away_team_id".format(cls.__name__),

backref=backref('away_friendly_matches'))

开发者ID:soccermetrics,项目名称:marcotti,代码行数:5,

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

orm设置bool型 python_Python orm.relationship方法代码示例相关推荐

  1. orm设置bool型 python_Python SQLAlchemy入门教程

    本文将以Mysql举例,介绍sqlalchemy的基本用法.其中,Python版本为2.7,sqlalchemy版本为1.1.6. 一. 介绍 SQLAlchemy是Python中最有名的ORM工具. ...

  2. orm设置bool型 python_python基础教程之基本内置数据类型介绍

    Python基本内置数据类型有哪些 一些基本数据类型,比如:整型(数字).字符串.元组.列表.字典和布尔类型. 随着学习进度的加深,大家还会接触到更多更有趣的数据类型,python初学者入门时先了解这 ...

  3. orm设置bool型 python_详解python的ORM中Pony用法

    Pony是Python的一种ORM,它允许使用生成器表达式来构造查询,通过将生成器表达式的抽象语法树解析成SQL语句.它也有在线ER图编辑器可以帮助你创建Model. 示例分析 Pony语句: sel ...

  4. java中elapseTime设置新时间,Java ApplicationLike.getApplicationStartElapsedTime方法代码示例...

    import com.tencent.tinker.loader.app.ApplicationLike; //导入方法依赖的package包/类 /** * if com.dx168.patchsd ...

  5. flag的具体用法python_Python Qt.WindowFlags方法代码示例

    # 需要导入模块: from PyQt5.QtCore import Qt [as 别名] # 或者: from PyQt5.QtCore.Qt import WindowFlags [as 别名] ...

  6. fmod函数python_python fmod函数_Python numpy.fmod方法代码示例

    本文整理汇总了Python中numpy.fmod方法的典型用法代码示例.如果您正苦于以下问题:Python numpy.fmod方法的具体用法?Python numpy.fmod怎么用?Python ...

  7. doc python 颜色_Python wordcloud.ImageColorGenerator方法代码示例

    本文整理汇总了Python中wordcloud.ImageColorGenerator方法的典型用法代码示例.如果您正苦于以下问题:Python wordcloud.ImageColorGenerat ...

  8. python管理工具ports_Python options.port方法代码示例

    本文整理汇总了Python中tornado.options.port方法的典型用法代码示例.如果您正苦于以下问题:Python options.port方法的具体用法?Python options.p ...

  9. python3 urllib3_Python urllib3.disable_warnings方法代码示例

    本文整理汇总了Python中requests.packages.urllib3.disable_warnings方法的典型用法代码示例.如果您正苦于以下问题:Python urllib3.disabl ...

最新文章

  1. Java 中 PO 与 VO 的区别
  2. 让 SAP Spartacus 某些 Component 不参与 SSR 的办法
  3. php 商品规格笛卡尔积,PHP 求多个数组的笛卡尔积,适用于求商品规格组合【原创】...
  4. Controller接口控制器详解(1)
  5. 红石科技机器人_《机器人殖民地》—游戏简评
  6. Python编程及应用--数据分析与科学计算可视化培训班
  7. thrift java first demo
  8. mysql 哨兵_第六课补充01——主从复制原理,哨兵机制
  9. (转)知乎:维度灾难
  10. 使用spreadjs vue版本
  11. Science观点:不同细菌物种间极少合作—合理利用细菌间普遍存在的竞争关系来替代抗生素...
  12. matlab中dzdx,MatConvnet工具箱使用手册翻译理解一
  13. ice的意思_ice是什么意思_ice的翻译_音标_读音_用法_例句_爱词霸在线词典
  14. Python解线性方程组的直接法(5)————平方根法求解线性方程组
  15. 写计算机课的作文,电脑课作文(小学生作文写不好怎么办)
  16. PHP如何实现微信网页授权
  17. 瑞鹄转债上市价格预测
  18. Dirichlet Multinomial Mixtures (DMM)的R实现
  19. 中地恒达水库大坝监测,倾斜监测系统(Guard-QJ)
  20. 年终奖发下来了!买个牛年限量款AirPods Pro送给大家!

热门文章

  1. 常用的删除sql语句
  2. 推荐四款最易上手的电脑版视频编辑软件
  3. mac输入拼音的方法
  4. ajax传递数组到controller
  5. puzzle(1521)纪念碑谷
  6. 设计师常用免费可商用字体下载
  7. SniperEliteV2没有声音的解决办法
  8. 【Spring学习34】Spring事务(4):事务属性之7种传播行为
  9. 微信小程序地图开发入门(一)
  10. java如何判断字符是否是字母?