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 #878

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

Solution #878

wants to merge 4 commits into from

Conversation

Bogdan-Rylov
Copy link

No description provided.

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,

Choose a reason for hiding this comment

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

overindented

movie_description: str,
genres_ids: list = None,
actors_ids: list = None,
movie_title: str,

Choose a reason for hiding this comment

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

fix indentation

@@ -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

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

@@ -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()

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?

show_time: str = None,
movie_id: int = None,
cinema_hall_id: int = None,
session_id: int,

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)

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)

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
Copy link

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

Comment on lines 27 to 34
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
]
Copy link

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

for ticket in tickets
]


def update_movie_session(
session_id: int,
show_time: str = None,
Copy link

Choose a reason for hiding this comment

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

fix annotation

Comment on lines 25 to 28
Ticket(
movie_session=MovieSession.objects.get(
id=ticket["movie_session"]
),
Copy link

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(

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

Copy link

@Oleksl888 Oleksl888 left a comment

Choose a reason for hiding this comment

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

Well done!

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