-
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
f #514
Closed
Closed
f #514
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dc47138
f
XOctOpus1 26a769b
f
XOctOpus1 e390001
Update services/movie.py
XOctOpus1 45b8893
f
XOctOpus1 9895ca4
f
XOctOpus1 14c231d
Merge remote-tracking branch 'origin/dev' into dev
XOctOpus1 8d79ecc
f
XOctOpus1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated by Django 4.0.2 on 2023-10-27 23:02 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('db', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='CinemaHall', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=255)), | ||
('rows', models.IntegerField()), | ||
('seats_in_row', models.IntegerField()), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Movie', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=255)), | ||
('description', models.TextField()), | ||
('actors', models.ManyToManyField(to='db.Actor')), | ||
('genres', models.ManyToManyField(to='db.Genre')), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='MovieSession', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('show_time', models.DateTimeField()), | ||
('cinema_hall', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='db.cinemahall')), | ||
('movie', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='db.movie')), | ||
], | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
db/migrations/0003_alter_movie_actors_alter_movie_genres.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.0.2 on 2023-10-27 20:25 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('db', '0002_cinemahall_movie_moviesession'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='movie', | ||
name='actors', | ||
field=models.ManyToManyField(related_name='actors', to='db.Actor'), | ||
), | ||
migrations.AlterField( | ||
model_name='movie', | ||
name='genres', | ||
field=models.ManyToManyField(related_name='genres', to='db.Genre'), | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
db/migrations/0004_alter_movie_actors_alter_movie_genres.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.0.2 on 2023-10-29 12:32 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('db', '0003_alter_movie_actors_alter_movie_genres'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='movie', | ||
name='actors', | ||
field=models.ManyToManyField(to='db.Actor'), | ||
), | ||
migrations.AlterField( | ||
model_name='movie', | ||
name='genres', | ||
field=models.ManyToManyField(to='db.Genre'), | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
db/migrations/0005_alter_movie_actors_alter_movie_genres.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.0.2 on 2023-10-29 12:44 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('db', '0004_alter_movie_actors_alter_movie_genres'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='movie', | ||
name='actors', | ||
field=models.ManyToManyField(related_name='movies', to='db.Actor'), | ||
), | ||
migrations.AlterField( | ||
model_name='movie', | ||
name='genres', | ||
field=models.ManyToManyField(related_name='movies', to='db.Genre'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from db.models import CinemaHall | ||
from django.db.models.query import QuerySet | ||
|
||
|
||
def get_cinema_halls() -> QuerySet[CinemaHall]: | ||
return CinemaHall.objects.all() | ||
|
||
|
||
def create_cinema_hall( | ||
hall_name: str, | ||
hall_rows: int, | ||
hall_seats_in_row: int | ||
) -> CinemaHall: | ||
return CinemaHall.objects.create( | ||
name=hall_name, | ||
rows=hall_rows, | ||
seats_in_row=hall_seats_in_row | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from db.models import Movie | ||
from django.db.models.query import QuerySet | ||
|
||
|
||
def get_movies( | ||
genres_ids: list[int] = None, | ||
actors_ids: list[int] = None | ||
) -> QuerySet[Movie]: | ||
|
||
queryset = Movie.objects.all() | ||
|
||
if genres_ids is not None: | ||
queryset = queryset.filter(genres__id__in=genres_ids) | ||
|
||
if actors_ids is not None: | ||
queryset = queryset.filter(actors__id__in=actors_ids) | ||
|
||
return queryset | ||
|
||
|
||
def get_movie_by_id(movie_id: int) -> Movie: | ||
return Movie.objects.get(id=movie_id) | ||
|
||
|
||
def create_movie( | ||
movie_title: str, | ||
movie_description: str, | ||
genres_ids: list[int] = None, | ||
actors_ids: list[int] = None | ||
) -> Movie: | ||
|
||
movie = Movie.objects.create( | ||
title=movie_title, | ||
description=movie_description | ||
) | ||
|
||
if genres_ids: | ||
movie.genres.set(genres_ids) | ||
|
||
if actors_ids: | ||
movie.actors.set(actors_ids) | ||
|
||
return movie |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import datetime | ||
from db.models import MovieSession, Movie, CinemaHall | ||
from django.db.models.query import QuerySet | ||
from typing import Optional | ||
|
||
|
||
def create_movie_session( | ||
movie_show_time: datetime.datetime, | ||
movie_id: int, | ||
cinema_hall_id: int | ||
) -> MovieSession: | ||
return MovieSession.objects.create( | ||
show_time=movie_show_time, | ||
cinema_hall_id=cinema_hall_id, | ||
movie_id=movie_id | ||
) | ||
|
||
|
||
def get_movies_sessions( | ||
session_date: Optional[datetime.date] = None | ||
) -> QuerySet[MovieSession]: | ||
queryset = MovieSession.objects.all() | ||
|
||
if session_date: | ||
queryset = queryset.filter(show_time__date=session_date) | ||
|
||
return queryset | ||
|
||
|
||
def get_movie_session_by_id(movie_session_id: int) -> MovieSession: | ||
return MovieSession.objects.get(id=movie_session_id) | ||
|
||
|
||
def update_movie_session( | ||
session_id: int, | ||
show_time: Optional[str] = None, | ||
movie_id: Optional[int] = None, | ||
cinema_hall_id: Optional[int] = None | ||
) -> None: | ||
movie_session_to_update = get_movie_session_by_id(session_id) | ||
if show_time: | ||
movie_session_to_update.show_time = show_time | ||
|
||
if movie_id is not None: | ||
movie = Movie.objects.get(id=movie_id) | ||
movie_session_to_update.movie = movie | ||
|
||
if cinema_hall_id is not None: | ||
cinema_hall = CinemaHall.objects.get(id=cinema_hall_id) | ||
movie_session_to_update.cinema_hall = cinema_hall | ||
|
||
movie_session_to_update.save() | ||
|
||
|
||
def delete_movie_session_by_id(session_id: int) -> None: | ||
movie_session_to_delete = get_movie_session_by_id(session_id) | ||
movie_session_to_delete.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,6 @@ | |
|
||
USE_I18N = True | ||
|
||
USE_TZ = False | ||
USE_TZ = True | ||
|
||
INSTALLED_APPS = ("db",) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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.
but there
s no need to change migrations. I thought that it
s better to let django make migrations