-
Notifications
You must be signed in to change notification settings - Fork 707
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 #726
base: master
Are you sure you want to change the base?
Solution #726
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.
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:
-
Typo in Method Parameter: The typo in the
perform_create
method parameter (serializere
instead ofserializer
) will cause aNameError
. This needs to be corrected to ensure the method functions properly. -
Incorrect Condition Check: The condition
if self.action == ("list", "retrieve"):
is incorrect becauseself.action
is a string, not a tuple. Please update this toif self.action in ["list", "retrieve"]:
to avoid logical errors. -
Validation Handling: The
full_clean()
method inTicketSerializer
'svalidate
method will raise aValidationError
for invalid tickets. Consider handling this exception to provide more user-friendly error messages. -
OrderSerializer Tickets Field: The
tickets
field inOrderSerializer
is not read-only, which allows ticket creation through the order serializer. Ensure thatTicketSerializer
correctly handles ticket creation, especially with its validation logic. -
Read-Only Movie Session: The
movie_session
field inTicketSerializer
is set to read-only, preventing setting or changing it during ticket creation or update. Confirm if this is intended, and if not, consider removingread_only=True
.
Please address these issues to ensure the functionality and integrity of the code. Once resolved, we can proceed with the approval. Keep up the great work! 🚀
✨ 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.
|
||
|
||
class TicketSerializer(serializers.ModelSerializer): | ||
movie_session = MovieSessionListSerializer(many=False, read_only=True) |
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.
In TicketSerializer
, the movie_session
field is set to read-only. This means that when creating or updating a ticket, the movie_session
cannot be set or changed through this serializer. Ensure this behavior is intended. If you need to allow setting movie_session
, consider removing read_only=True
.
|
||
|
||
class OrderSerializer(serializers.ModelSerializer): | ||
tickets = TicketSerializer(many=True, read_only=False, allow_empty=False) |
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.
In OrderSerializer
, the tickets
field is not read-only, which allows creating tickets through the order serializer. Ensure that the TicketSerializer
is correctly handling the creation of tickets, especially considering the validation logic in TicketSerializer
.
row=data.get("row"), | ||
seat=data.get("seat"), | ||
) | ||
ticket.full_clean() |
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 full_clean()
method in TicketSerializer
's validate
method will raise a ValidationError
if the ticket is invalid. Ensure that this is the intended behavior, as it will prevent saving invalid tickets. Consider handling the exception to provide more user-friendly error messages if needed.
cinema/views.py
Outdated
@@ -43,6 +57,28 @@ def get_serializer_class(self): | |||
|
|||
return MovieSerializer | |||
|
|||
def get_queryset(self): | |||
queryset = super().get_queryset() | |||
if self.action == ("list", "retrieve"): |
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 condition if self.action == ("list", "retrieve"):
is incorrect. The self.action
attribute is a string, not a tuple. You should use if self.action in ["list", "retrieve"]:
to check if the action is either 'list' or 'retrieve'.
cinema/views.py
Outdated
def get_queryset(self): | ||
return self.queryset.filter(user=self.request.user) | ||
|
||
def perform_create(self, serializere): |
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.
There is a typo in the perform_create
method parameter name. It should be serializer
instead of serializere
. This typo will cause a NameError
when trying to call save
on serializere
.
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.
Great job on addressing many of the previous issues in your code! 🎉 Your Pull Request is approved to help you move forward with your learning journey. However, there are a few critical areas that need attention:
-
Validation Error Message: In the
Ticket
model'sclean
method, the error message forValidationError
could be clearer. Consider rephrasing it to avoid confusion about the valid range. -
Unique Constraint: Update the
unique_together
constraint in theTicket
model'sMeta
class to useUniqueConstraint
for better readability and future compatibility. -
Read-Only Movie Session: The
movie_session
field inTicketSerializer
is currently set toread_only=True
. If your intention is to allow setting or changing this field during ticket creation or update, you should adjust this setting. -
Validation Handling: The
full_clean()
method inTicketSerializer
'svalidate
method will raise aValidationError
for invalid tickets. Consider handling this exception to provide more user-friendly error messages. -
Security Concerns: Ensure that the
SECRET_KEY
is not hardcoded and exposed in the settings file. Use environment variables or a separate configuration file to manage sensitive information. Also, remember to setDEBUG
toFalse
in production environments.
Your efforts to correct previous issues are commendable, and these changes will enhance the functionality and security of your application. Keep up the good work, and continue to learn and improve your coding skills! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
|
||
|
||
class TicketSerializer(serializers.ModelSerializer): | ||
movie_session = MovieSessionListSerializer(many=False, read_only=True) |
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 movie_session
field is set to read-only in TicketSerializer
. If you intend to allow setting or changing the movie session during ticket creation or update, consider removing read_only=True
.
row=data.get("row"), | ||
seat=data.get("seat"), | ||
) | ||
ticket.full_clean() |
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 full_clean()
method will raise a ValidationError
for invalid tickets. Consider handling this exception to provide more user-friendly error messages.
No description provided.