-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
181 additions
and
0 deletions.
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ venv/ | |
**__pycache__/ | ||
*.pyc | ||
**db.sqlite3 | ||
.gitignore |
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 2025-01-14 11:59 | ||
|
||
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(related_name='movies', to='db.Actor')), | ||
('genres', models.ManyToManyField(related_name='movies', 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')), | ||
], | ||
), | ||
] |
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,19 @@ | ||
from django.db.models import QuerySet | ||
|
||
from db.models import CinemaHall | ||
|
||
|
||
def get_cinema_halls() -> 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 | ||
) |
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,36 @@ | ||
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: | ||
movies = Movie.objects.all() | ||
if genres_ids: | ||
movies = movies.filter(genres__id__in=genres_ids) | ||
if actors_ids: | ||
movies = movies.filter(actors__id__in=actors_ids) | ||
return movies | ||
|
||
|
||
def get_movie_by_id(movie_id: int) -> Movie: | ||
return Movie.objects.get(pk=movie_id) | ||
|
||
|
||
def create_movie( | ||
movie_title: str, | ||
movie_description: str, | ||
genres_ids: list[int] = None, | ||
actors_ids: list[int] = None | ||
) -> None: | ||
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) |
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,51 @@ | ||
from datetime import datetime | ||
|
||
from django.db.models import QuerySet | ||
|
||
from db.models import MovieSession | ||
|
||
|
||
def create_movie_session( | ||
movie_show_time: datetime, | ||
movie_id: int, | ||
cinema_hall_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: datetime = None) -> QuerySet: | ||
movies_sessions = MovieSession.objects.all() | ||
if session_date is not None: | ||
movies_sessions = movies_sessions.filter(show_time__date=session_date) | ||
return movies_sessions | ||
|
||
|
||
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: | ||
movie_session = get_movie_session_by_id(session_id) | ||
|
||
if show_time is not None: | ||
movie_session.show_time = show_time | ||
|
||
if movie_id is not None: | ||
movie_session.movie_id = movie_id | ||
|
||
if cinema_hall_id is not None: | ||
movie_session.cinema_hall_id = cinema_hall_id | ||
movie_session.save() | ||
|
||
|
||
def delete_movie_session_by_id(session_id: int) -> None: | ||
get_movie_session_by_id(session_id).delete() |