-
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
result #1073
base: master
Are you sure you want to change the base?
result #1073
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated by Django 5.1.4 on 2025-01-10 19:42 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
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')), | ||
], | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 5.1.4 on 2025-01-10 19:39 | ||
|
||
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='movies', to='db.actor'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the |
||
), | ||
migrations.AlterField( | ||
model_name='movie', | ||
name='genres', | ||
field=models.ManyToManyField(related_name='movies', to='db.genre'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that the |
||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.db.models import QuerySet | ||
|
||
from db.models import CinemaHall | ||
|
||
|
||
def get_cinema_hall() -> QuerySet: | ||
return CinemaHall.objects.all() | ||
|
||
|
||
def create_cinema_hall( | ||
hall_name: str, | ||
hall_rows: int, | ||
hall_seats_in_row: int, | ||
) -> None: | ||
CinemaHall.objects.create( | ||
name=hall_name, | ||
rows=hall_rows, | ||
seats_in_row=hall_seats_in_row | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from django.db.models import QuerySet | ||
|
||
from db.models import Movie | ||
|
||
|
||
def get_movies( | ||
genres_ids: list[int] = None, | ||
actors_ids: list[int] = None, | ||
) -> QuerySet[Movie]: | ||
queryset = Movie.objects.all() | ||
|
||
if genres_ids: | ||
queryset = queryset.filter( | ||
genres__id__in=genres_ids | ||
).distinct() | ||
|
||
if actors_ids: | ||
queryset = queryset.filter( | ||
actors__id__in=actors_ids | ||
).distinct() | ||
|
||
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, | ||
) -> None: | ||
new_movie = Movie.objects.create( | ||
title=movie_title, | ||
description=movie_description | ||
) | ||
if genres_ids: | ||
new_movie.genres.set(genres_ids) | ||
|
||
if actors_ids: | ||
new_movie.actors.set(actors_ids) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from datetime import datetime | ||
from django.db.models import QuerySet | ||
from db.models import MovieSession | ||
|
||
|
||
def create_movie_session( | ||
movie_show_time: datetime, | ||
cinema_hall_id: int, | ||
movie_id: int, | ||
) -> None: | ||
MovieSession.objects.create( | ||
show_time=movie_show_time, | ||
cinema_hall_id=cinema_hall_id, | ||
movie_id=movie_id | ||
) | ||
|
||
|
||
def get_movies_sessions( | ||
session_date: str = None | ||
) -> QuerySet[MovieSession]: | ||
queryset = MovieSession.objects.all() | ||
if session_date: | ||
queryset = queryset.filter(show_time__date=session_date) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure that |
||
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: datetime = None, | ||
movie_id: int = None, | ||
cinema_hall_id: int = None | ||
) -> None: | ||
upd_session = MovieSession.objects.get(id=session_id) | ||
if show_time: | ||
upd_session.show_time = show_time | ||
if movie_id: | ||
upd_session.movie_id = movie_id | ||
if cinema_hall_id: | ||
upd_session.cinema_hall_id = cinema_hall_id | ||
upd_session.save() | ||
|
||
|
||
def delete_movie_session_by_id(session_id: int) -> None: | ||
MovieSession.objects.get(id=session_id).delete() |
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",) |
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.
Ensure that the
actor
andgenre
models exist in thedb
app. TheManyToManyField
references should point to existing models to avoid runtime errors.