Read the guideline before starting.
In db/models.py
you already have tables you created earlier. Now
you have to create tables:
Movie
, with such fields:- char field
title
, the title of the movie with the maximum length of 255 characters. - text field
description
- many to many field
actors
, which is related to the tableActor
- many to many field
genres
, which is related to the tableGenre
- char field
There should be implemented the string representation of the movie:
speed = Movie.objects.create(title="Speed", description="Speed movie")
print(speed)
# Speed
CinemaHall
, with such fields:- char field
name
, the name of the cinema hall with the maximum length of 255 characters - integer field
rows
, the number of rows of seats in the hall - integer field
seats_in_row
, the number of seats in each row
- char field
There should be implemented string representation of the hall and
the capacity
property that returns total number of seats in the hall:
blue = CinemaHall.objects.create(name="Blue", rows=9, seats_in_row= 13)
print(blue)
# Blue
print(blue.capacity)
# 117
MovieSession
, with such field:- date time field
show_time
, the date and the time of the movie session performance - foreign key
cinema_hall
, the hall where the movie session is performed, references to the tableCinemaHall
- foreign key
movie
, the movie to be shown, references to the tableMovie
- date time field
There should be implemented string representation of the movie session, that shows the movie name, the date, and the time of the movie session:
import datetime
movie_session = MovieSession.objects.create(
show_time=datetime.datetime(year=2021, month=11, day=29, hour=16, minute=40),
cinema_hall=blue,
movie=speed
)
print(movie_session)
# Speed 2021-11-29 16:40:00
Use the following command to load prepared data from fixture to test and debug your code:
python manage.py loaddata cinema_db_data.json
.
Also, implement a few services for these tables. A service
represents module with functions with queries for the certain
table.
Create a package services
next to the package db
. Inside
the package services
create such service modules:
movie.py
, implements such functions:get_movies
, takes optionalgenres_ids
- a list of genres ids, optionalactors_ids
- a list of actors ids.- If
genres_ids
andactors_ids
are not provided, the method returns all movies - If both
genres_ids
andactors_ids
are provided, the method returns movies, that have at least one genre fromgenres_ids
and one actor fromactors_ids
. - If only
genres_ids
is provided, the method returns the queryset with movies, that have at least one genre fromgenres_ids
- If only
actors_ids
is provided, the method returns the queryset with movies, that have at least one actor fromactors_ids
- If
get_movie_by_id
, takesmovie_id
- id of the movie, returns movie with the provided id.create_movie
, takesmovie_title
,movie_description
, optionalgenres_ids
and optionalactors_ids
,genres_ids
andactors_ids
are the list of genres ids and the list of actors ids respectively, method creates movie with provided title and description, add him genres ifgenres_ids
is provided, add him actors ifactors_ids
is provided.
Note: You can use suffix __id
to get access to the field id
of related table inside .filter()
method. You also can
use the suffix __in
to check if the value is in list/tuple.
cinema_hall.py
, implements such functions:get_cinema_halls
, returns all cinema hallscreate_cinema_hall
, takeshall_name
,hall_rows
,hall_seats_in_row
, creates cinema hall with provided parameters
movie_session.py
, implements such functions:create_movie_session
, takesmovie_show_time
- show time of the movie,movie_id
- id of the movie,cinema_hall_id
- id of the cinema hall. Creates movie session with provided parametersget_movies_sessions
, takes optional stringsession_date
in such form: "year-month-day"- if
session_date
is provided - returns all movie sessions for this date - else returns all movies sessions
- if
get_movie_session_by_id
, takesmovie_session_id
- id of the movie session, returns movie session with the provided idupdate_movie_session
, takessession_id
, optionalshow_time
, optionalmovie_id
, optionalcinema_hall_id
. Update movie session with providedsession_id
and set fields if appropriate values are provideddelete_movie_session_by_id
, takessession_id
- id of session, deletes movie session with the provided id
Note: You can use suffix __date
to get access to date of the
DateTimeField