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

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

solution #864

wants to merge 11 commits into from

Conversation

HalynaRohatska
Copy link

No description provided.

db/models.py Outdated
created_at = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE

Choose a reason for hiding this comment

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

related name missing here

db/models.py Outdated
movie_session = models.ForeignKey(
to=MovieSession,
on_delete=models.CASCADE,
related_name="movie_sessions"

Choose a reason for hiding this comment

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

this is wrong related name

db/models.py Outdated
order = models.ForeignKey(
to=Order,
on_delete=models.CASCADE,
related_name="orders"

Choose a reason for hiding this comment

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

related name is how tickets will be accessed from Order model. Please correct

db/models.py Outdated
max_rows = self.movie_session.cinema_hall.rows
max_seats = self.movie_session.cinema_hall.seats_in_row

if max_rows < self.row:

Choose a reason for hiding this comment

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

this doesn't validate vs negative numbers

db/models.py Outdated
constraints = [
UniqueConstraint(
fields=["row", "seat", "movie_session"],
name="unique_ticket_seat_row_movie_session")

Choose a reason for hiding this comment

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

well done on naming contraint in a right way 👏
But please move Meta class right under fields definition - it is placed there as a convetion in django

)
Ticket.objects.create(
order=order,
movie_session=movie_session,

Choose a reason for hiding this comment

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

you can pass movie_session_id instead of passing an object here

services/user.py Outdated


def get_user(user_id: int) -> User:
return get_user_model().objects.filter(id=user_id).first()

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: str | None = None,
last_name: str | None = None
) -> None:
user = get_user_model().objects.filter(id=user_id).first()

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 function here

services/user.py Outdated
) -> None:
user = get_user_model().objects.filter(id=user_id).first()

if not user:

Choose a reason for hiding this comment

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

no need for this check - if user doesnt exist let the error happen

settings.py Outdated

AUTH_USER_MODEL = "db.User"

AUTH_PASSWORD_VALIDATORS = [

Choose a reason for hiding this comment

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

you don't need to add this in this task

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.

it's better to use from django.conf import settings because you may have settings folder of another settings file and python will import incorrect settings

db/models.py Outdated
Comment on lines 81 to 87
related_name="movie_session_tickets"
)
order = models.ForeignKey(
to=Order,
on_delete=models.CASCADE,
related_name="order_tickets"
)
Copy link

Choose a reason for hiding this comment

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

you overwhelm it too much
You have MovieSession object. For example

my_session = MovieSession.objects.filter(show_date='2024-09-03', movie='Harry Potter').first()
I know it's MovieSession, now I want to get all tickets of this movie
my_session.movie_session_tickets.all() # it's a bit redundant to add "movie_session" in related_name because I know that my_session is MovieSession object
so instead it's better to do
my_session.tickets.all()

Fix everywhere ;)

db/models.py Outdated
Comment on lines 105 to 108
if max_rows < self.row or self.row < 0:
raise ValidationError(
{"row": [f"row number must be in available range: "
f"(1, rows): (1, {self.row - 1})"]}
Copy link

Choose a reason for hiding this comment

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

what if row is 0? 0 < 0 will not return false and raise error but you mention here that row should be at least 1

db/models.py Outdated
{"row": [f"row number must be in available range: "
f"(1, rows): (1, {self.row - 1})"]}
)
if max_seats < self.seat or self.seat < 0:
Copy link

Choose a reason for hiding this comment

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

the same here

def get_taken_seats(movie_session_id: int) -> list[dict]:
tickets = Ticket.objects.filter(movie_session_id=movie_session_id)

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.

still not fixed

def create_order(
tickets: list[dict],
username: str,
date: datetime = None
Copy link

Choose a reason for hiding this comment

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

datetime or None


def get_orders(
username: str | None = None,
) -> QuerySet:
Copy link

Choose a reason for hiding this comment

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

specify what kind of data this queryset contains

if actors_ids:
movie.actors.set(actors_ids)

return movie

Choose a reason for hiding this comment

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

You don't need return anything in create/update/delete functions, check everywhere

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.

4 participants