-
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
Showing
18 changed files
with
130 additions
and
88 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 |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
venv/ | ||
.pytest_cache/ | ||
**__pycache__/ | ||
db.sqlite3 |
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
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,41 +1,66 @@ | ||
from rest_framework import serializers | ||
|
||
from cinema.models import Genre, Actor, CinemaHall, Movie, MovieSession | ||
|
||
|
||
class GenreSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Genre | ||
fields = ["id", "name"] | ||
|
||
|
||
class ActorSerializer(serializers.ModelSerializer): | ||
full_name = serializers.CharField(source="get_full_name", read_only=True) | ||
|
||
class Meta: | ||
model = Actor | ||
fields = ["id", "first_name", "last_name", "full_name"] | ||
|
||
|
||
class CinemaHallSerializer(serializers.ModelSerializer): | ||
capacity = serializers.IntegerField(read_only=True) | ||
|
||
class Meta: | ||
model = CinemaHall | ||
fields = ["id", "name", "rows", "seats_in_row", "capacity"] | ||
|
||
|
||
class MovieSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Movie | ||
fields = ["id", "title", "description", "duration", "genres", "actors"] | ||
|
||
|
||
class MovieSessionSerializer(serializers.ModelSerializer): | ||
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", "cinema_hall", "movie_title", "cinema_hall_name", "cinema_hall_capacity"] | ||
from rest_framework import serializers | ||
|
||
from cinema.models import Actor, CinemaHall, Genre, Movie, MovieSession | ||
|
||
|
||
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 CinemaHallSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = CinemaHall | ||
fields = ["id", "name", "rows", "seats_in_row", "capacity"] | ||
|
||
|
||
class MovieSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Movie | ||
fields = ["id", "title", "description", "duration", "genres", "actors"] | ||
|
||
|
||
class MovieListSerializer(MovieSerializer): | ||
genres = serializers.SlugRelatedField( | ||
slug_field="name", queryset=Genre.objects.all(), many=True | ||
) | ||
actors = serializers.SlugRelatedField( | ||
slug_field="full_name", queryset=Actor.objects.all(), many=True | ||
) | ||
|
||
|
||
class MovieDetailSerializer(MovieSerializer): | ||
genres = GenreSerializer(many=True) | ||
actors = ActorSerializer(many=True) | ||
|
||
|
||
class MovieSessionSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = MovieSession | ||
fields = ["id", "show_time", "movie", "cinema_hall"] | ||
|
||
|
||
class MovieSessionListSerializer(serializers.ModelSerializer): | ||
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 | ||
exclude = ["cinema_hall", "movie"] | ||
|
||
|
||
class MovieSessionDetailSerializer(MovieSessionSerializer): | ||
movie = MovieListSerializer() | ||
cinema_hall = CinemaHallSerializer(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
from django.test import TestCase | ||
|
||
from rest_framework import status | ||
from rest_framework.test import APIClient | ||
|
||
|
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,5 +1,4 @@ | ||
from django.test import TestCase | ||
|
||
from rest_framework import status | ||
from rest_framework.test import APIClient | ||
|
||
|
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
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,5 +1,6 @@ | ||
from django.contrib import admin | ||
from django.contrib.auth.admin import UserAdmin | ||
|
||
from .models import User | ||
|
||
admin.site.register(User, UserAdmin) |
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