Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first #684

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

first #684

wants to merge 6 commits into from

Conversation

egor250330
Copy link

No description provided.

Copy link

@OleksiukStepan OleksiukStepan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done. Fix small mistakes and it will be great.



class CinemaHallSerializer(serializers.Serializer):
name = serializers.CharField(max_length=25)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't include the id field, the API responses for actors will not show the id, and you won't be able to use it for updates or references in related models (like for associating an actor with a movie). This can be problematic if you're dealing with many-to-many relationships or need to update or delete specific actor records.
Add id field in every serializer



class GenreSerializer(serializers.Serializer):
name = serializers.CharField(max_length=25)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's recommended to maintain the same max_length for both models and serializers.
Also fix in Actor

rows = serializers.IntegerField()
seats_in_row = serializers.IntegerField()

def create(self, validated_data):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add type hints for parameters and return in each file and function

cinema/views.py Outdated
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use shorter version here (from our previous task):
serializer.is_valid(raise_exception=True)
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)

cinema/views.py Outdated
serializer = GenreSerializer(genre, data=request.data, partial=True)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

cinema/views.py Outdated
if request.method == "POST":
serializer = MovieSerializer(data=request.data)
def post(self, request) -> Response:
serializer = GenreSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here (serializer.is_valid(raise_exception=True))


class GenreSerializer(serializers.Serializer):
id = serializers.IntegerField(read_only=True)
name = serializers.CharField(max_length=25)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having different max_length constraints in your Django model and serializer can lead to inconsistencies and potential issues. Fix it everywhere.

cinema/admin.py Outdated
Comment on lines 6 to 8
@admin.register(Movie)
class MovieAdmin(admin.ModelAdmin):
pass
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use admin.site.register instead

cinema/urls.py Outdated
Comment on lines 1 to 2
from django.urls import path, include
from rest_framework import routers
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 blank line between different groups of imports

cinema/views.py Outdated
Comment on lines 1 to 5
from rest_framework.response import Response
from rest_framework import status
from rest_framework import status, mixins, generics, viewsets

from django.shortcuts import get_object_or_404
from rest_framework.views import APIView
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reorder imports alphabetically

@egor250330 egor250330 requested a review from MNDonut October 1, 2024 07:21
Copy link

@Arsen-hrynevych Arsen-hrynevych left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall ok

Comment on lines +83 to +93
def get(self, request, *args, **kwargs):
return self.retrieve(request, *args, **kwargs)

def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs)

def patch(self, request, *args, **kwargs):
return self.partial_update(request, *args, **kwargs)

def delete(self, request, *args, **kwargs):
return self.destroy(request, *args, **kwargs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant code: you have already had this methods

Comment on lines +66 to +70
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants