-
Notifications
You must be signed in to change notification settings - Fork 858
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_py-tickets-and-orders_1 #557
base: master
Are you sure you want to change the base?
Conversation
services/movie_session.py
Outdated
movie_session = (MovieSession.objects.prefetch_related("ticket_set"). | ||
get(id=movie_session_id)) | ||
tickets = movie_session.ticket_set.values("row", "seat") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you start query from MovieSession, in this case you do 2 queries instead of 1
services/user.py
Outdated
if email: | ||
user.email = email | ||
if first_name: | ||
user.first_name = first_name | ||
if last_name: | ||
user.last_name = last_name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate code, the same into create_user
services/movie_session.py
Outdated
return [ | ||
{ | ||
"row": ticket["row"], | ||
"seat": ticket["seat"] | ||
} | ||
for ticket in tickets | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return [ | |
{ | |
"row": ticket["row"], | |
"seat": ticket["seat"] | |
} | |
for ticket in tickets | |
] | |
return tickets |
services/order.py
Outdated
if username: | ||
return (Order.objects.select_related("user"). | ||
filter(user__username=username)) | ||
return Order.objects.all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if username: | |
return (Order.objects.select_related("user"). | |
filter(user__username=username)) | |
return Order.objects.all() | |
orders = Order.objects.select_related("user") | |
if username: | |
orders = orders.filter(user__username=username) | |
return orders |
services/order.py
Outdated
) | ||
|
||
|
||
def get_orders(username: str = None) -> Order: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this function return Order
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several changes were requested.
services/movie.py
Outdated
movie.actors.set(actors_ids) | ||
|
||
return movie | ||
with transaction.atomic(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case you apply transaction.atomic
to the whole function body, you could use transaction.atomic
as a decorator for a function.
services/order.py
Outdated
date: str = None | ||
) -> None: | ||
order = Order.objects.create( | ||
user=User.objects.get( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use get_user_model()
instead of User
here and in other places where applicable as mentioned in the checklist.
services/order.py
Outdated
) | ||
|
||
|
||
def get_orders(username: str = None) -> QuerySet: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could additionally specify that a QuerySet
of Order
is returned in the return type annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
No description provided.