-
Notifications
You must be signed in to change notification settings - Fork 636
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 #652
base: master
Are you sure you want to change the base?
Solution #652
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.
Nice!
cinema/tests/test_actor_api.py
Outdated
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.
Revert all tests
cinema/serializers.py
Outdated
movie = MovieListSerializer(many=False, read_only=True) | ||
cinema_hall = CinemaHallSerializer(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.
many
by default is False
cinema/serializers.py
Outdated
order = Order.objects.create(**validated_data) | ||
for ticket_data in tickets_data: | ||
Ticket.objects.create(order=order, **ticket_data) | ||
return 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.
In create/update/delete functions you don't need return anything
cinema/views.py
Outdated
genres_ids = [ | ||
int(genre_id.strip(" ")) | ||
for genre_id in genres.split(",") | ||
] |
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.
Code duplicate, put in separate function
cinema/views.py
Outdated
@@ -34,6 +38,29 @@ class MovieViewSet(viewsets.ModelViewSet): | |||
queryset = Movie.objects.all() | |||
serializer_class = MovieSerializer | |||
|
|||
def get_queryset(self): | |||
queryset = self.queryset |
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.
call super method instead of accesing this attribute directly
solve N+1 problem
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.
still not fixed
cinema/views.py
Outdated
@@ -48,6 +75,32 @@ class MovieSessionViewSet(viewsets.ModelViewSet): | |||
queryset = MovieSession.objects.all() | |||
serializer_class = MovieSessionSerializer | |||
|
|||
def get_queryset(self): | |||
queryset = self.queryset |
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 here
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.
still not fixed
cinema/views.py
Outdated
genres__id__in=self._params_to_int(genres) | ||
) | ||
|
||
return queryset |
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.
call distinct here()
cinema/views.py
Outdated
pagination_class = OrderPagination | ||
|
||
def get_queryset(self): | ||
queryset = self.queryset |
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.
call super method instead of accesing this attribute directly
cinema/views.py
Outdated
|
||
def get_queryset(self): | ||
queryset = super().get_queryset() | ||
title = self.request.query_params.get("title") |
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 would make sense only on list action
cinema/views.py
Outdated
@@ -56,3 +112,32 @@ def get_serializer_class(self): | |||
return MovieSessionDetailSerializer | |||
|
|||
return MovieSessionSerializer | |||
|
|||
|
|||
class OrderPagination(LimitOffsetPagination): |
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.
is better design to put pagination in separate file
cinema/views.py
Outdated
def get_queryset(self): | ||
queryset = super().get_queryset() | ||
|
||
date = self.request.query_params.get("date") |
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.
here also - this only applicable to list action
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.
It's not understandable for me, why in list we should call super, but in other cases no, or what?
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.
@AndriiHamasa Oleksandr meant that you should handle query params only when it's list action because query params are passed only for GET(for list) http method
cinema/views.py
Outdated
@@ -34,6 +38,29 @@ class MovieViewSet(viewsets.ModelViewSet): | |||
queryset = Movie.objects.all() | |||
serializer_class = MovieSerializer | |||
|
|||
def get_queryset(self): | |||
queryset = self.queryset |
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.
still not fixed
cinema/views.py
Outdated
@@ -48,6 +75,32 @@ class MovieSessionViewSet(viewsets.ModelViewSet): | |||
queryset = MovieSession.objects.all() | |||
serializer_class = MovieSessionSerializer | |||
|
|||
def get_queryset(self): | |||
queryset = self.queryset |
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.
still not fixed
cinema/views.py
Outdated
def get_queryset(self): | ||
queryset = super().get_queryset() | ||
|
||
date = self.request.query_params.get("date") |
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.
@AndriiHamasa Oleksandr meant that you should handle query params only when it's list action because query params are passed only for GET(for list) http method
No description provided.