-
Notifications
You must be signed in to change notification settings - Fork 857
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 #1 #377
Solution #1 #377
Conversation
db/models.py
Outdated
] | ||
|
||
def clean(self) -> None: | ||
if not self.row <= self.movie_session.cinema_hall.rows: |
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.
This check will be ok if you used PositiveIntegerField. You can receive self.row -3, for example, and it will be no error.
db/models.py
Outdated
} | ||
) | ||
|
||
if not self.seat <= self.movie_session.cinema_hall.seats_in_row: |
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 the same here
services/order.py
Outdated
row=ticket["row"], | ||
seat=ticket["seat"] | ||
) | ||
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.
You made save() in if check. If you don't change anything after creation no need to use save() more.
services/user.py
Outdated
email=email, | ||
first_name=first_name, | ||
last_name=last_name | ||
) |
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 need to create user with optional fields (email, first_name, last_name) just in that case if they were provided.
services/order.py
Outdated
row=ticket["row"], | ||
seat=ticket["seat"] | ||
) | ||
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.
Maybe I explained not the best way. I meant you had already save() in if check, so you don't need additional one after the remaining part of your code. You need to make save() just in if check like below:
if date:
order.created_at = date
order.save()
services/user.py
Outdated
last_name: str = "" | ||
email: str = None, | ||
first_name: str = None, | ||
last_name: str = 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.
You can replace emal, first_name, last_name with **kwargs. Then you need to create some list/tuple with "email", "first_name", "last_name", and create your object 'User' by username and password. Then you need to unpack your kwargs and iterate one by one, checking if such key exist in your kwargs.items() and checking if value of this key is not "" or None. In this case after your check you can use setattr() to add this value to your 'User' object
services/user.py
Outdated
user.first_name = first_name | ||
|
||
if last_name: | ||
user.last_name = last_name |
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 make the same here. update_user(user_id: int, password: str, **kwargs)
services/movie_session.py
Outdated
return list(Ticket.objects.filter( | ||
movie_session_id=movie_session_id).values("row", "seat")) |
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.
bad formmating here
services/order.py
Outdated
def create_order( | ||
tickets: list[dict], | ||
username: str, | ||
date: str = None) -> 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.
same
services/user.py
Outdated
user_data = { | ||
"username": username, | ||
"password": password, | ||
} | ||
|
||
if email: | ||
user_data["email"] = email | ||
|
||
if first_name: | ||
user_data["first_name"] = first_name | ||
|
||
if last_name: | ||
user_data["last_name"] = last_name |
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.
try to optimize this
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.
👍
No description provided.