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 #727

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

Solution #727

wants to merge 8 commits into from

Conversation

Atikiho
Copy link

@Atikiho Atikiho commented Dec 12, 2024

No description provided.

Copy link

@Den-k0 Den-k0 left a comment

Choose a reason for hiding this comment

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

lgtm


from cinema.models import Genre, Actor, CinemaHall, Movie, MovieSession
from cinema.models import Genre, Actor, CinemaHall, Movie, MovieSession, Order
Copy link

Choose a reason for hiding this comment

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

Group imports using () if needed

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! There are a few critical issues that need to be addressed before we can approve the pull request. The OrderSerializer has a problem with handling tickets due to the read-only field, which will cause a KeyError. Additionally, the get_tickets_available property in the MovieSession class does not correctly calculate available tickets for a specific session. Lastly, filtering by actors__id__icontains is not suitable for an ID field. Please address these issues to ensure the functionality meets the task requirements. Keep up the great work, and I look forward to your improvements! 🚀

✨ 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.

cinema/models.py Outdated
Comment on lines 63 to 67
@property
def get_tickets_available(self):
return (self.cinema_hall.rows
* self.cinema_hall.seats_in_row
- len(Ticket.objects.all()))

Choose a reason for hiding this comment

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

The get_tickets_available property incorrectly calculates the number of available tickets. It should filter the tickets by the specific MovieSession instance rather than using all tickets. Consider using self.tickets.count() to get the number of tickets for this session.

Comment on lines +125 to +127
def create(self, validated_data):
with transaction.atomic():
tickets_data = validated_data.pop("tickets")

Choose a reason for hiding this comment

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

The create method in OrderSerializer attempts to pop tickets from validated_data, but tickets is marked as read-only in the serializer, meaning it won't be part of validated_data. This will raise a KeyError. Consider revising the approach to handle ticket creation separately or adjust the serializer to accept ticket data.

cinema/views.py Outdated
if title:
queryset = queryset.filter(title__icontains=title)
if actors:
queryset = queryset.filter(actors__id__icontains=actors)

Choose a reason for hiding this comment

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

Filtering by actors__id__icontains is not appropriate for an ID field. Consider using actors__id=actors if actors is expected to be a single ID, or adjust the logic to handle multiple IDs if necessary.

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.

Review Summary

Great job on addressing most of the issues in your cinema application! 🎬 Your models, serializers, views, and URL configurations are well-structured and adhere to Django and Django REST Framework conventions. Here are some key points and areas for improvement:

  1. OrderSerializer KeyError: The OrderSerializer is still using a read-only TicketSerializer for the tickets field. This will cause a KeyError when trying to create an order because the create method expects writable fields to create Ticket instances. Please ensure that the serializer can handle ticket creation properly.

  2. get_tickets_available Calculation: The get_tickets_available property in the MovieSession class is now correctly implemented. It calculates the available tickets by subtracting the count of tickets from the cinema hall's total capacity. Verify that the tickets related name is correctly set up and used to ensure accurate calculations.

  3. Filtering by Actor ID: The filtering logic in the MovieViewSet is now correctly implemented using actors__id=actors, which is appropriate for ID fields. This improvement enhances the functionality of your application.

  4. Configuration Settings: Remember to set DEBUG to False in production for security reasons and configure ALLOWED_HOSTS appropriately for deployment.

Your progress is commendable, and the decision to approve this pull request is to help you move forward with your learning. Please review the comments and address the mentioned issues to improve your code further. Keep up the great work and continue learning from these experiences! 🚀

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

Comment on lines +63 to +67
@property
def get_tickets_available(self):
return (self.cinema_hall.rows
* self.cinema_hall.seats_in_row
- self.tickets.count())

Choose a reason for hiding this comment

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

The get_tickets_available property should correctly calculate the number of available tickets for a movie session. Ensure that it accounts for the total capacity of the cinema hall minus the number of tickets already sold. The current implementation seems to do this, but please verify that the tickets related name is correctly set up and used.

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