-
Notifications
You must be signed in to change notification settings - Fork 857
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 #878
base: master
Are you sure you want to change the base?
Solution #878
Conversation
services/movie.py
Outdated
from django.db.models import QuerySet | ||
|
||
from db.models import Movie | ||
|
||
|
||
def get_movies( | ||
genres_ids: list[int] = None, | ||
actors_ids: list[int] = None, | ||
genres_ids: Optional[list[int]] = None, |
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.
overindented
services/movie.py
Outdated
movie_description: str, | ||
genres_ids: list = None, | ||
actors_ids: list = None, | ||
movie_title: str, |
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.
fix indentation
services/movie_session.py
Outdated
@@ -4,7 +4,7 @@ | |||
|
|||
|
|||
def create_movie_session( | |||
movie_show_time: str, movie_id: int, cinema_hall_id: int | |||
movie_show_time: str, movie_id: int, cinema_hall_id: int |
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 should pay attention when you use tools for formatting code now indentation is broken everywhere
services/movie_session.py
Outdated
@@ -24,11 +24,19 @@ def get_movie_session_by_id(movie_session_id: int) -> MovieSession: | |||
return MovieSession.objects.get(id=movie_session_id) | |||
|
|||
|
|||
def get_taken_seats(movie_session_id: int) -> list[dict]: | |||
tickets = MovieSession.objects.get(id=movie_session_id).tickets.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.
can you use values() method here?
services/movie_session.py
Outdated
show_time: str = None, | ||
movie_id: int = None, | ||
cinema_hall_id: int = None, | ||
session_id: int, |
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.
indentation
services/user.py
Outdated
|
||
|
||
def get_user(user_id: int) -> get_user_model(): | ||
return get_user_model().objects.get(id=user_id) |
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 pk here
services/user.py
Outdated
first_name: Optional[str] = None, | ||
last_name: Optional[str] = None | ||
) -> None: | ||
user = get_user_model().objects.get(id=user_id) |
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 can reuse your get_user here to keep it DRY
db/models.py
Outdated
from django.db import models | ||
from django.db.models import UniqueConstraint | ||
|
||
import settings |
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 from django.conf import settings
to use real global settings because you may have multiple settings files or folders with this name
services/movie_session.py
Outdated
def get_taken_seats(movie_session_id: int) -> list[dict]: | ||
tickets = MovieSession.objects.get( | ||
id=movie_session_id | ||
).tickets.values("row", "seat") | ||
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.
you actually do the same job twice using .values() and creating a list of dicts.
.values() returns queryset of dicts. you can use this fact
services/movie_session.py
Outdated
for ticket in tickets | ||
] | ||
|
||
|
||
def update_movie_session( | ||
session_id: int, | ||
show_time: str = None, |
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.
fix annotation
services/order.py
Outdated
Ticket( | ||
movie_session=MovieSession.objects.get( | ||
id=ticket["movie_session"] | ||
), |
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.
set movie_session_id as you get id instead of fetching that object
@@ -24,11 +26,19 @@ def get_movie_session_by_id(movie_session_id: int) -> MovieSession: | |||
return MovieSession.objects.get(id=movie_session_id) | |||
|
|||
|
|||
def get_taken_seats(movie_session_id: int) -> list[dict]: | |||
return list( | |||
MovieSession.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.
here you could reuse get_movie_session_by_id
function defined above
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.
Well done!
No description provided.