-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Resloved #516
base: master
Are you sure you want to change the base?
Resloved #516
Conversation
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('db', '0001_initial'), |
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.
change ' to ", use Black
services/movie_session.py
Outdated
|
||
|
||
def delete_movie_session_by_id(session_id: int) -> None: | ||
MovieSession.objects.get(id=session_id).delete() |
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_movies_sessions here
services/movie_session.py
Outdated
if show_time: | ||
session.show_time = show_time | ||
if movie_id: | ||
session.movie = Movie.objects.get(id=movie_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 get_movie_by_id here
db/models.py
Outdated
class Movie(models.Model): | ||
title = models.CharField(max_length=255) | ||
description = models.TextField() | ||
actors = models.ManyToManyField(Actor, related_name="actors", blank=True) |
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.
wrong related 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.
db/models.py
Outdated
title = models.CharField(max_length=255) | ||
description = models.TextField() | ||
actors = models.ManyToManyField(Actor, related_name="actors", blank=True) | ||
genres = models.ManyToManyField(Genre, related_name="genres", blank=True) |
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.
same here
services/cinema_hall.py
Outdated
from django.db.models import QuerySet | ||
|
||
|
||
def get_cinema_halls() -> 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.
def get_cinema_halls() -> QuerySet: | |
def get_cinema_halls() -> QuerySet[CinemaHall]: |
services/movie_session.py
Outdated
if show_time: | ||
session.show_time = show_time | ||
if movie_id: | ||
session.movie = get_movie_by_id(movie_id) | ||
if cinema_hall_id: | ||
session.cinema_hall = get_cinema_halls().get(id=cinema_hall_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.
if show_time: | |
session.show_time = show_time | |
if movie_id: | |
session.movie = get_movie_by_id(movie_id) | |
if cinema_hall_id: | |
session.cinema_hall = get_cinema_halls().get(id=cinema_hall_id) | |
if show_time is not None: | |
session.show_time = show_time | |
if movie_id is not None: | |
session.movie_id = movie_id | |
if cinema_hall_id is not None: | |
session.cinema_hall_id = cinema_hall_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.
It leads to error because we can not assign values directly, he only accepts instance of the classes and I can't find how to pass ids directly. I just can't pass tests with these changes
services/movie_session.py
Outdated
show_time: datetime = None, | ||
movie_id: int = None, | ||
cinema_hall_id: 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.
better to use Optional in 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.
Ok, added optional None
FAILED tests/test_main.py::test_movie_session_service_update_movie_session_movie - ValueError: Cannot assign "5": "MovieSession.movie" must be a "Movie" instance. |
services/movie_session.py
Outdated
cinema_hall = CinemaHall.objects.get(id=cinema_hall_id) | ||
movie = Movie.objects.get(id=movie_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.
No need to get objects
You can create objects by id: .create(movie_id=movie_id,.....
services/movie_session.py
Outdated
if session_date: | ||
return MovieSession.objects.filter(show_time__date=session_date) | ||
return MovieSession.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 session_date: | |
return MovieSession.objects.filter(show_time__date=session_date) | |
return MovieSession.objects.all() | |
movie_sessions = MovieSession.objects.all() | |
if session_date: | |
return movie_sessions.filter(show_time__date=session_date) | |
return movie_sessions |
This can help support your code in future
No description provided.