-
Notifications
You must be signed in to change notification settings - Fork 899
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 #952
base: master
Are you sure you want to change the base?
solution #952
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.
Good job!
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 pull request! 😊 While your code is generally well-structured and follows good practices, there are a few critical issues that need to be addressed before we can approve it:
-
Order Model's
created_at
Field: TheOrder
model should have thecreated_at
field set withauto_now_add=True
to automatically fill this field during creation. Currently, it usesdefault=datetime.now
, which does not meet the requirement. -
Use of
transaction.atomic
: Ensure that thecreate_movie
function inservices/movie.py
usestransaction.atomic
to maintain atomicity, as specified in the task description.
These issues are important as they impact the functionality and requirements of the task. Once these are resolved, your code will be in great shape! Keep up the great work, and feel free to reach out if you have any questions or need further assistance. 🚀
✨ 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.
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='User', |
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.
Creating a custom User
model can be useful for extending user functionality, but ensure that this is necessary and that the AUTH_USER_MODEL
setting in your Django settings is updated to point to this model.
name='Order', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created_at', models.DateTimeField(auto_now_add=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 Order
model uses settings.AUTH_USER_MODEL
for the user
ForeignKey, which is correct. Ensure that AUTH_USER_MODEL
is set correctly in your Django settings if you are using a custom user model.
db/models.py
Outdated
@@ -1,4 +1,9 @@ | |||
from django.contrib.auth.models import AbstractUser, User |
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 import of User
from django.contrib.auth.models
is unnecessary since you are defining a custom User
model inheriting from AbstractUser
. Consider removing this import to avoid confusion.
|
||
class Order(models.Model): | ||
created_at = models.DateTimeField(default=datetime.now) | ||
user = models.ForeignKey(settings.AUTH_USER_MODEL, |
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 Order
model uses settings.AUTH_USER_MODEL
for the user
ForeignKey, which is correct. Ensure that AUTH_USER_MODEL
is set correctly in your Django settings if you are using a custom user model.
from django.db.models import QuerySet | ||
|
||
from db.models import Movie | ||
|
||
|
||
def get_movies( | ||
genres_ids: list[int] = None, | ||
actors_ids: list[int] = None, | ||
genres_ids: list[int] = None, |
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 type hint list[int]
is only supported in Python 3.9 and later. If you need compatibility with earlier Python versions, consider using List[int]
from the typing
module.
actors_ids: list = None, | ||
movie_title: str, | ||
movie_description: str, | ||
genres_ids: list = None, |
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 type hint list
for genres_ids
and actors_ids
is not specific. Consider using Optional[List[int]]
for better clarity and compatibility with Python versions earlier than 3.9.
@@ -42,3 +42,14 @@ def update_movie_session( | |||
|
|||
def delete_movie_session_by_id(session_id: int) -> None: | |||
MovieSession.objects.get(id=session_id).delete() | |||
|
|||
|
|||
def get_taken_seats(movie_session_id: int) -> list[dict[str, int]]: |
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 type hint list[dict[str, int]]
is only supported in Python 3.9 and later. If you need compatibility with earlier Python versions, consider using List[Dict[str, int]]
from the typing
module.
from db.models import Order, Ticket | ||
|
||
|
||
def create_order(tickets: list[dict], |
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 type hint list[dict]
is only supported in Python 3.9 and later. If you need compatibility with earlier Python versions, consider using List[Dict]
from the typing
module.
return order | ||
|
||
|
||
def get_orders(username: Optional[str] = None) -> list[Order]: |
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 type hint list[Order]
is only supported in Python 3.9 and later. If you need compatibility with earlier Python versions, consider using List[Order]
from the typing
module.
if username: | ||
user.username = username |
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.
When updating the username, ensure that the new username is unique to prevent integrity errors. Consider adding validation to handle this scenario.
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.
Review Summary
Great job on addressing the previous issues and improving the code! 🎉 The Pull Request is approved to help you move forward with your learning journey. Here are some key points and suggestions for further improvement:
-
Order Model's
created_at
Field: You've correctly usedauto_now_add=True
for thecreated_at
field, ensuring it is automatically filled during creation. However, be cautious with manually setting this field, as it can lead to inconsistencies. Consider removing this logic unless there's a specific need for custom dates. -
Import Statement for Settings: In the models file, the import statement should be corrected to
from django.conf import settings
to properly access the settings module in Django. -
Use of
transaction.atomic
: Excellent use of@transaction.atomic
in thecreate_movie
function to ensure atomicity, which is crucial for maintaining data integrity. -
General Code Structure: Overall, the code is well-structured and follows Django's best practices. The use of validation methods and exception handling is commendable.
Remember, addressing these minor issues will enhance the robustness and maintainability of your code. Keep up the good work and continue learning from each iteration! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
from django.db import models | ||
|
||
import settings |
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 import statement import settings
is incorrect. In Django, you should import settings using from django.conf import settings
to access the settings module.
if date: | ||
order.created_at = date | ||
order.save() |
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.
Manually setting the created_at
field can lead to inconsistencies, as it overrides the automatic timestamping provided by auto_now_add=True
. Consider removing this logic unless there's a specific requirement to allow custom dates.
No description provided.