-
Notifications
You must be signed in to change notification settings - Fork 722
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
base: master
Are you sure you want to change the base?
first #684
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
cinema/serializers.py
Outdated
rows = serializers.IntegerField() | ||
seats_in_row = serializers.IntegerField() | ||
|
||
def create(self, validated_data): |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
@admin.register(Movie) | ||
class MovieAdmin(admin.ModelAdmin): | ||
pass |
There was a problem hiding this comment.
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
from django.urls import path, include | ||
from rest_framework import routers |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reorder imports alphabetically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall ok
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) |
There was a problem hiding this comment.
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
def get(self, request, *args, **kwargs): | ||
return self.list(request, *args, **kwargs) | ||
|
||
def post(self, request, *args, **kwargs): | ||
return self.create(request, *args, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same here
No description provided.