-
Notifications
You must be signed in to change notification settings - Fork 714
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
1 parent
1f225be
commit c86b00f
Showing
13 changed files
with
288 additions
and
44 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
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
23 changes: 23 additions & 0 deletions
23
cinema/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.4 on 2024-12-02 13:13 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("cinema", "0004_alter_genre_name"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="movie", | ||
name="actors", | ||
field=models.ManyToManyField(related_name="movies", to="cinema.actor"), | ||
), | ||
migrations.AlterField( | ||
model_name="movie", | ||
name="genres", | ||
field=models.ManyToManyField(related_name="movies", to="cinema.genre"), | ||
), | ||
] |
43 changes: 43 additions & 0 deletions
43
cinema/migrations/0006_alter_moviesession_cinema_hall_and_more.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,43 @@ | ||
# Generated by Django 4.0.4 on 2024-12-02 13:14 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("cinema", "0005_alter_movie_actors_alter_movie_genres"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="moviesession", | ||
name="cinema_hall", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="sessions", | ||
to="cinema.cinemahall", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="moviesession", | ||
name="movie", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="sessions", | ||
to="cinema.movie", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="order", | ||
name="user", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="orders", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
] |
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
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 |
---|---|---|
@@ -1 +1,88 @@ | ||
# write serializers here | ||
from rest_framework import serializers | ||
from cinema.models import (Actor, | ||
CinemaHall, | ||
Movie, | ||
MovieSession, | ||
Order, | ||
Ticket, | ||
Genre) | ||
|
||
|
||
class CinemaHallSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = CinemaHall | ||
fields = ("id", "name", "rows", "seats_in_row", "capacity") | ||
|
||
|
||
class GenreSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Genre | ||
fields = ( | ||
"id", | ||
"name", | ||
) | ||
|
||
|
||
class ActorSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Actor | ||
fields = ("id", "first_name", "last_name", "full_name") | ||
|
||
|
||
class MovieSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Movie | ||
fields = ("id", "title", "duration", "description", "genres", "actors") | ||
|
||
|
||
class MovieListSerializer(MovieSerializer): | ||
genres = serializers.SlugRelatedField( | ||
many=True, | ||
read_only=True, | ||
slug_field="name") | ||
|
||
actors = serializers.StringRelatedField(many=True) | ||
|
||
class Meta: | ||
model = Movie | ||
fields = "__all__" | ||
|
||
|
||
class MovieRetrieveSerializer(MovieSerializer): | ||
genres = GenreSerializer(many=True, read_only=True) | ||
actors = ActorSerializer(many=True, read_only=True) | ||
|
||
|
||
class MovieSessionSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = MovieSession | ||
fields = ("id", "show_time", "movie", "cinema_hall") | ||
read_only_fields = ("id",) | ||
|
||
|
||
class MovieSessionListSerializer(MovieSessionSerializer): | ||
movie_title = serializers.CharField(source="movie.title", read_only=True) | ||
|
||
cinema_hall_name = serializers.CharField( | ||
source="cinema_hall.name", | ||
read_only=True) | ||
|
||
cinema_hall_capacity = serializers.IntegerField( | ||
source="cinema_hall.capacity", read_only=True | ||
) | ||
|
||
class Meta: | ||
model = MovieSession | ||
fields = ( | ||
"id", | ||
"show_time", | ||
"movie_title", | ||
"cinema_hall_name", | ||
"cinema_hall_capacity", | ||
) | ||
read_only_fields = ("id",) | ||
|
||
|
||
class MovieSessionRetrieveSerializer(MovieSessionSerializer): | ||
movie = MovieListSerializer(many=False, read_only=True) | ||
cinema_hall = CinemaHallSerializer(many=False, read_only=True) |
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
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
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
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
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 |
---|---|---|
@@ -1 +1,23 @@ | ||
# write urls here | ||
from django.urls import path, include | ||
from rest_framework import routers | ||
from cinema.views import ( | ||
CinemaHallViewSet, | ||
GenreViewSet, | ||
ActorViewSet, | ||
MovieViewSet, | ||
MovieSessionViewSet, | ||
) | ||
|
||
app_name = "cinema" | ||
|
||
router = routers.DefaultRouter() | ||
router.register("cinema_halls", CinemaHallViewSet) | ||
router.register("genres", GenreViewSet) | ||
router.register("actors", ActorViewSet) | ||
router.register("movies", MovieViewSet) | ||
|
||
router.register("movie_sessions", MovieSessionViewSet) | ||
|
||
urlpatterns = [ | ||
path("", include(router.urls)), | ||
] |
Oops, something went wrong.