Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #563

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Solution #563

wants to merge 3 commits into from

Conversation

loplicat
Copy link

No description provided.

Comment on lines 7 to 29
def create_order(
tickets: list[dict],
username: str,
date: str = None
) -> None:
with transaction.atomic():
user = User.objects.get(username=username)
order = Order.objects.create(user=user)

if date:
order.created_at = date
order.save()

for ticket in tickets:
row = ticket.get("row")
seat = ticket.get("seat")
movie_session_id = ticket.get("movie_session")
Ticket.objects.create(
row=row,
seat=seat,
movie_session_id=movie_session_id,
order=order
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the @transaction.atomic decorator to wrap the create_order for better readability

services/user.py Outdated
first_name: str = None,
last_name: str = None
) -> None:
user = User.objects.get(id=user_id)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY. Use previous created method here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for tips! I've already implemented changes

Copy link

@Polyakiv-Andrey Polyakiv-Andrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants