Skip to content

Commit 31e25ad

Browse files
committed
Cleanup.
1 parent 970e68a commit 31e25ad

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
SQLALCHEMY_DATABASE_PEM = environ.get("SQLALCHEMY_DATABASE_PEM")
1313

1414
# Reset data after each run
15-
CLEANUP_DATA = True
15+
CLEANUP_DATA = False

sqlalchemy_tutorial/part3_relationships/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from .joins import get_all_comments, get_all_posts
55
from .objects import create_comment_objects, create_post_object, create_user_objects
6-
from .orm import create_comment, create_user, create_post
6+
from .orm import create_comment, create_post, create_user
77

88

99
def create_relationships():

sqlalchemy_tutorial/part3_relationships/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Comment(Base):
4545
created_at = Column(DateTime, server_default=func.now())
4646

4747
# Relationships
48-
user = relationship("User", backref="comments")
48+
user = relationship("User", backref="comment")
4949

5050
def __repr__(self):
5151
return "<Comment %r>" % self.id

sqlalchemy_tutorial/part3_relationships/orm.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def create_user(session: Session, user: User) -> User:
2020
:return: Optional[User]
2121
"""
2222
try:
23-
existing_user = session.query(User).filter(User.username == user.username).first()
23+
existing_user = (
24+
session.query(User).filter(User.username == user.username).first()
25+
)
2426
if existing_user is None:
2527
session.add(user) # Add the user
2628
session.commit() # Commit the change
@@ -81,9 +83,7 @@ def create_comment(session: Session, comment: Comment) -> Comment:
8183
try:
8284
session.add(comment) # Add the Comment
8385
session.commit() # Commit the change
84-
LOGGER.success(
85-
f"Created comment {comment} posted by user {comment.user.username}"
86-
)
86+
LOGGER.success(f"Created comment {comment} from user {comment.user.username}.")
8787
return comment
8888
except IntegrityError as e:
8989
LOGGER.error(e.orig)

0 commit comments

Comments
 (0)