summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPaul Brown <paul90brown@gmail.com>2017-03-17 00:23:49 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2017-03-18 14:42:43 -0400
commit8dad0f93e8a7f1dcd79ff5c3640c997667d06248 (patch)
tree8f01f5dd284350d7de9621ac76e51dda1944790e /examples
parent8f7cf2990f9010ea4924f2525318dff0ba1028d7 (diff)
downloadsqlalchemy-8dad0f93e8a7f1dcd79ff5c3640c997667d06248.tar.gz
fix pep8 errors in adjacency_list example
(cherry picked from commit ff230f1862892eb2b479ed85e6858a82159b435f)
Diffstat (limited to 'examples')
-rw-r--r--examples/adjacency_list/__init__.py1
-rw-r--r--examples/adjacency_list/adjacency_list.py59
2 files changed, 30 insertions, 30 deletions
diff --git a/examples/adjacency_list/__init__.py b/examples/adjacency_list/__init__.py
index 5d80363e4..65ce311e6 100644
--- a/examples/adjacency_list/__init__.py
+++ b/examples/adjacency_list/__init__.py
@@ -15,4 +15,3 @@ E.g.::
.. autosource::
"""
-
diff --git a/examples/adjacency_list/adjacency_list.py b/examples/adjacency_list/adjacency_list.py
index 9e62bc0be..3c9144323 100644
--- a/examples/adjacency_list/adjacency_list.py
+++ b/examples/adjacency_list/adjacency_list.py
@@ -1,32 +1,32 @@
from sqlalchemy import Column, ForeignKey, Integer, String, create_engine
-from sqlalchemy.orm import Session, relationship, backref,\
- joinedload_all
+from sqlalchemy.orm import Session, relationship, backref, joinedload_all
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.collections import attribute_mapped_collection
Base = declarative_base()
+
class TreeNode(Base):
__tablename__ = 'tree'
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, ForeignKey(id))
name = Column(String(50), nullable=False)
- children = relationship("TreeNode",
-
- # cascade deletions
- cascade="all, delete-orphan",
+ children = relationship(
+ "TreeNode",
+ # cascade deletions
+ cascade="all, delete-orphan",
- # many to one + adjacency list - remote_side
- # is required to reference the 'remote'
- # column in the join condition.
- backref=backref("parent", remote_side=id),
+ # many to one + adjacency list - remote_side
+ # is required to reference the 'remote'
+ # column in the join condition.
+ backref=backref("parent", remote_side=id),
- # children will be represented as a dictionary
- # on the "name" attribute.
- collection_class=attribute_mapped_collection('name'),
- )
+ # children will be represented as a dictionary
+ # on the "name" attribute.
+ collection_class=attribute_mapped_collection('name'),
+ )
def __init__(self, name, parent=None):
self.name = name
@@ -34,18 +34,19 @@ class TreeNode(Base):
def __repr__(self):
return "TreeNode(name=%r, id=%r, parent_id=%r)" % (
- self.name,
- self.id,
- self.parent_id
- )
+ self.name,
+ self.id,
+ self.parent_id
+ )
def dump(self, _indent=0):
return " " * _indent + repr(self) + \
- "\n" + \
- "".join([
- c.dump(_indent + 1)
- for c in self.children.values()]
- )
+ "\n" + \
+ "".join([
+ c.dump(_indent + 1)
+ for c in self.children.values()
+ ])
+
if __name__ == '__main__':
engine = create_engine('sqlite://', echo=True)
@@ -94,14 +95,14 @@ if __name__ == '__main__':
msg("Tree after save:\n %s", node.dump())
- msg("Emptying out the session entirely, "
- "selecting tree on root, using eager loading to join four levels deep.")
+ msg("Emptying out the session entirely, selecting tree on root, using "
+ "eager loading to join four levels deep.")
session.expunge_all()
node = session.query(TreeNode).\
- options(joinedload_all("children", "children",
- "children", "children")).\
- filter(TreeNode.name == "rootnode").\
- first()
+ options(joinedload_all("children", "children",
+ "children", "children")).\
+ filter(TreeNode.name == "rootnode").\
+ first()
msg("Full Tree:\n%s", node.dump())