Skip to content

Commit

Permalink
'Solution'
Browse files Browse the repository at this point in the history
  • Loading branch information
TsvetanKichuk committed Sep 28, 2024
1 parent ef4f0bd commit 151c0d1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
19 changes: 13 additions & 6 deletions cinema/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def create(self, validated_data):
def update(self, instance, validated_data):
instance.title = validated_data.get("title", instance.title)
instance.description = validated_data.get(
"description", instance.description
"description",
instance.description
)
instance.duration = validated_data.get("duration", instance.duration)

Expand All @@ -35,10 +36,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.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 Expand Up @@ -67,8 +68,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
5 changes: 2 additions & 3 deletions cinema/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ActorList,
ActorDetail,
GenreList,
GenreDetail
GenreDetail,
)

router = routers.DefaultRouter()
Expand All @@ -20,6 +20,5 @@
path("genres/<int:pk>/", GenreDetail.as_view(), name="genre-detail"),
path("actors/", ActorList.as_view(), name="actor-list"),
path("actors/<int:pk>/", ActorDetail.as_view(), name="actor-detail"),
]

]
app_name = "cinema"
8 changes: 3 additions & 5 deletions cinema/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def delete(self, request, pk):


class ActorList(
mixins.ListModelMixin,
mixins.CreateModelMixin,
generics.GenericAPIView
mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView
):
queryset = Actor.objects.all()
serializer_class = ActorSerializer
Expand All @@ -68,7 +66,7 @@ class ActorDetail(
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView
generics.GenericAPIView,
):

queryset = Actor.objects.all()
Expand All @@ -90,7 +88,7 @@ class CinemaHallViewSet(
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
viewsets.GenericViewSet
viewsets.GenericViewSet,
):

queryset = CinemaHall.objects.all()
Expand Down

0 comments on commit 151c0d1

Please sign in to comment.