Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
FursykIvan committed Dec 15, 2024
1 parent b0eadae commit 3db5b6f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
15 changes: 12 additions & 3 deletions cinema/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ def create(self, validated_data):
return Actor.objects.create(**validated_data)

def update(self, instance, validated_data):
instance.first_name = validated_data.get("first_name", instance.first_name)
instance.last_name = validated_data.get("last_name", instance.last_name)
instance.first_name = validated_data.get(
"first_name",
instance.first_name
)
instance.last_name = validated_data.get(
"last_name",
instance.last_name
)

instance.save()

Expand Down Expand Up @@ -68,7 +74,10 @@ def create(self, validated_data):
def update(self, instance, validated_data):
instance.name = validated_data.get("name", instance.name)
instance.rows = validated_data.get("rows", instance.rows)
instance.seats_in_row = validated_data.get("seats_in_row", instance.seats_in_row)
instance.seats_in_row = validated_data.get(
"seats_in_row",
instance.seats_in_row
)

instance.save()

Expand Down
19 changes: 15 additions & 4 deletions cinema/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from django.urls import path, include
from rest_framework.routers import DefaultRouter

from cinema.views import GenreAPIView, ActorGenericAPIView, CinemaHallViewSet, MovieModelViewSet
from cinema.views import (
GenreAPIView,
ActorGenericAPIView,
CinemaHallViewSet,
MovieModelViewSet
)

app_name = "cinema"

Expand All @@ -25,7 +30,13 @@
path("genres/", GenreAPIView.as_view(), name="genre-list"),
path("genres/<int:pk>/", GenreAPIView.as_view(), name="genre-detail"),
path("actors/", ActorGenericAPIView.as_view(), name="actor-list"),
path("actors/<int:pk>/", ActorGenericAPIView.as_view(), name="actor-detail"),
path("cinema_halls/", cinema_hall_list, name="cinema-hall-list"),
path("cinema_halls/<int:pk>/", cinema_hall_detail, name="cinema-hall-detail"),
path("actors/<int:pk>/",
ActorGenericAPIView.as_view(),
name="actor-detail"),
path("cinema_halls/",
cinema_hall_list,
name="cinema-hall-list"),
path("cinema_halls/<int:pk>/",
cinema_hall_detail,
name="cinema-hall-detail"),
]
5 changes: 4 additions & 1 deletion cinema/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from rest_framework.viewsets import GenericViewSet

from cinema.models import Movie, Genre, Actor, CinemaHall
from cinema.serializers import MovieSerializer, GenreSerializer, ActorSerializer, CinemaHallSerializer
from cinema.serializers import (MovieSerializer,
GenreSerializer,
ActorSerializer,
CinemaHallSerializer)


class GenreAPIView(APIView):
Expand Down

0 comments on commit 3db5b6f

Please sign in to comment.