Skip to content

Commit

Permalink
reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Katkalov committed Oct 13, 2023
1 parent 4b72440 commit 83ec2e3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 41 deletions.
1 change: 0 additions & 1 deletion cinema/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="movie",
name="actors",
field=models.ManyToManyField(related_name="movies", to="cinema.actor"),
field=models.ManyToManyField(
related_name="movies", to="cinema.actor"
),
),
migrations.AddField(
model_name="movie",
name="genres",
field=models.ManyToManyField(related_name="movies", to="cinema.genre"),
field=models.ManyToManyField(
related_name="movies", to="cinema.genre"
),
),
]
7 changes: 1 addition & 6 deletions cinema/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,4 @@ class Meta:
class CinemaHallSerializer(serializers.ModelSerializer):
class Meta:
model = CinemaHall
fields = [
"id",
"name",
"rows",
"seats_in_row"
]
fields = ["id", "name", "rows", "seats_in_row"]
42 changes: 10 additions & 32 deletions cinema/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from rest_framework.views import APIView
Expand All @@ -15,12 +14,7 @@

from django.shortcuts import get_object_or_404

from cinema.models import (
Movie,
Genre,
Actor,
CinemaHall
)
from cinema.models import Movie, Genre, Actor, CinemaHall
from cinema.serializers import (
MovieSerializer,
GenreSerializer,
Expand All @@ -39,8 +33,12 @@ def post(self, request: Request) -> Response:
serialized_data = GenreSerializer(data=request.data)
if serialized_data.is_valid():
serialized_data.save()
return Response(serialized_data.data, status=status.HTTP_201_CREATED)
return Response(serialized_data.errors, status=status.HTTP_400_BAD_REQUEST)
return Response(
serialized_data.data, status=status.HTTP_201_CREATED
)
return Response(
serialized_data.errors, status=status.HTTP_400_BAD_REQUEST
)


class GenreDetail(APIView):
Expand Down Expand Up @@ -72,11 +70,7 @@ def delete(self, request: Request, pk: int) -> Response:
return Response(status=status.HTTP_204_NO_CONTENT)


class ActorList(
ListModelMixin,
CreateModelMixin,
GenericAPIView
):
class ActorList(ListModelMixin, CreateModelMixin, GenericAPIView):
queryset = Actor.objects.all()
serializer_class = ActorSerializer

Expand All @@ -91,7 +85,7 @@ class ActorDetail(
RetrieveModelMixin,
UpdateModelMixin,
DestroyModelMixin,
GenericAPIView
GenericAPIView,
):
queryset = Actor.objects.all()
serializer_class = ActorSerializer
Expand All @@ -109,29 +103,13 @@ def delete(self, request: Request, *args, **kwargs) -> Response:
return self.destroy(request, *args, **kwargs)


@api_view(["GET", "POST"])
def movie_list(request):
if request.method == "GET":
movies = Movie.objects.all()
serializer = MovieSerializer(movies, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)

if request.method == "POST":
serializer = MovieSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


class CinemaHallViewSet(
ListModelMixin,
CreateModelMixin,
RetrieveModelMixin,
UpdateModelMixin,
DestroyModelMixin,
GenericViewSet
GenericViewSet,
):
queryset = CinemaHall.objects.all()
serializer_class = CinemaHallSerializer
Expand Down

0 comments on commit 83ec2e3

Please sign in to comment.