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

Solution #709

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

Conversation

VladimirDolhyi
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Thank you for your hard work on this project! 😊 While your code is mostly well-structured and meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Critical Issue in models.py: The Ticket model's clean method references count_rows and count_seats_in_row attributes that do not exist in the CinemaHall model. This will cause errors during ticket validation and needs to be fixed to ensure the functionality of your application.

  2. Type Annotations: The task requires type annotations in class methods, which are currently missing in your viewsets and serializers. Adding these will improve code readability and maintainability.

  3. Redundant .all() Method: The use of the .all() method before .prefetch_related() and .select_related() in your viewsets is unnecessary and should be removed for optimal performance.

Once these issues are resolved, your code will be in great shape! Keep up the good work, and don't hesitate to reach out if you need any help. 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

.gitignore Show resolved Hide resolved
cinema/models.py Show resolved Hide resolved
Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

Great job on your progress! 🎉 While your code is mostly well-structured and follows Django conventions, there are a few critical issues that need attention to ensure functionality and performance:

  1. Critical Issue in models.py: The Ticket model's clean method references non-existent attributes count_rows and count_seats_in_row in the CinemaHall model. This will cause errors during ticket validation and should be corrected.

  2. Type Annotations: The task requires type annotations for class methods. Adding these to your viewsets and serializers will enhance code readability and maintainability.

  3. Redundant .all() Method: The use of .all() before .prefetch_related() and .select_related() in your viewsets is redundant. Removing .all() will optimize performance.

  4. Minor Issue in .gitignore: There's an extra space before db.sqlite3. Removing it will ensure consistency and avoid potential issues with ignoring the file.

These improvements are crucial for the functionality and performance of your code. Please address these issues in future revisions to enhance your learning experience. Keep up the good work and continue to learn from these challenges! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

@@ -6,3 +6,4 @@
venv/
.pytest_cache/
**__pycache__/
db.sqlite3

Choose a reason for hiding this comment

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

There is an extra space before db.sqlite3. It is recommended to remove this space to ensure consistency and avoid potential issues with ignoring the file.

Comment on lines +6 to +81
class CinemaHallSerializer(serializers.ModelSerializer):

class Meta:
model = CinemaHall
fields = ["id", "name", "rows", "seats_in_row", "capacity"]


class GenreSerializer(serializers.ModelSerializer):

class Meta:
model = Genre
fields = "__all__"


class ActorSerializer(serializers.ModelSerializer):

class Meta:
model = Actor
fields = ["id", "first_name", "last_name", "full_name"]


class MovieSerializer(serializers.ModelSerializer):

class Meta:
model = Movie
fields = "__all__"


class MovieListSerializer(MovieSerializer):
genres = serializers.SlugRelatedField(
many=True,
read_only=True,
slug_field="name",
)
actors = serializers.SlugRelatedField(
many=True,
read_only=True,
slug_field="full_name",
)


class MovieRetrieveSerializer(MovieSerializer):
genres = GenreSerializer(many=True, read_only=True)
actors = ActorSerializer(many=True, read_only=True)


class MovieSessionSerializer(serializers.ModelSerializer):

class Meta:
model = MovieSession
fields = "__all__"


class MovieSessionListSerializer(serializers.ModelSerializer):
movie_title = serializers.CharField(source="movie.title", read_only=True)
cinema_hall_name = serializers.CharField(
source="cinema_hall.name", read_only=True
)
cinema_hall_capacity = serializers.IntegerField(
source="cinema_hall.capacity", read_only=True
)

class Meta:
model = MovieSession
fields = [
"id",
"show_time",
"movie_title",
"cinema_hall_name",
"cinema_hall_capacity"
]


class MovieSessionRetrieveSerializer(MovieSessionSerializer):
movie = MovieListSerializer()
cinema_hall = CinemaHallSerializer()

Choose a reason for hiding this comment

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

The task requires type annotations for class methods. Consider adding type annotations to the methods in your serializers to improve code readability and maintainability.



class CinemaHallViewSet(viewsets.ModelViewSet):
queryset = CinemaHall.objects.all()

Choose a reason for hiding this comment

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

The use of .all() before .prefetch_related() and .select_related() is redundant. You can directly use CinemaHall.objects.prefetch_related() or CinemaHall.objects.select_related() in the get_queryset method to optimize performance.



class MovieViewSet(viewsets.ModelViewSet):
queryset = Movie.objects.all()

Choose a reason for hiding this comment

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

The use of .all() before .prefetch_related() is redundant. You can directly use Movie.objects.prefetch_related() in the get_queryset method to optimize performance.



class MovieSessionViewSet(viewsets.ModelViewSet):
queryset = MovieSession.objects.all()

Choose a reason for hiding this comment

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

The use of .all() before .select_related() is redundant. You can directly use MovieSession.objects.select_related() in the get_queryset method to optimize performance.

Comment on lines +17 to +63
class CinemaHallViewSet(viewsets.ModelViewSet):
queryset = CinemaHall.objects.all()
serializer_class = CinemaHallSerializer


class GenreViewSet(viewsets.ModelViewSet):
queryset = Genre.objects.all()
serializer_class = GenreSerializer


class ActorViewSet(viewsets.ModelViewSet):
queryset = Actor.objects.all()
serializer_class = ActorSerializer


class MovieViewSet(viewsets.ModelViewSet):
queryset = Movie.objects.all()

def get_serializer_class(self):
if self.action == "list":
return MovieListSerializer
elif self.action == "retrieve":
return MovieRetrieveSerializer
return MovieSerializer

def get_queryset(self):
queryset = self.queryset
if self.action in ("list", "retrieve"):
return queryset.prefetch_related("genres", "actors")
return queryset


class MovieSessionViewSet(viewsets.ModelViewSet):
queryset = MovieSession.objects.all()

def get_serializer_class(self):
if self.action == "list":
return MovieSessionListSerializer
elif self.action == "retrieve":
return MovieSessionRetrieveSerializer
return MovieSessionSerializer

def get_queryset(self):
queryset = self.queryset
if self.action in ("list", "retrieve"):
return queryset.select_related("movie", "cinema_hall")
return queryset

Choose a reason for hiding this comment

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

The task requires type annotations for class methods. Consider adding type annotations to the methods in your viewsets to improve code readability and maintainability.

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.

3 participants