-
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
not solution, i need check because have a little problem with git #662
base: master
Are you sure you want to change the base?
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.
You need to withit qna((
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.
ok
cinema/serializers.py
Outdated
@@ -35,6 +45,10 @@ class MovieListSerializer(MovieSerializer): | |||
many=True, read_only=True, slug_field="full_name" | |||
) | |||
|
|||
class Meta: | |||
model = Movie | |||
fields = MovieSerializer.Meta.fields + ("genres", "actors") |
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 inherit from MovieSerializer and it already has genres and actors fields in Meta
cinema/views.py
Outdated
@@ -11,7 +15,7 @@ | |||
MovieSessionListSerializer, | |||
MovieDetailSerializer, | |||
MovieSessionDetailSerializer, | |||
MovieListSerializer, | |||
MovieListSerializer, OrderSerializer, OrderListSerializer, |
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.
continue with each import on new line
cinema/views.py
Outdated
return [int(num) for num in query.split(",")] | ||
|
||
def get_queryset(self): | ||
query_set = 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.
How do you solve N+1 problem here?
cinema/views.py
Outdated
@@ -56,3 +91,48 @@ def get_serializer_class(self): | |||
return MovieSessionDetailSerializer | |||
|
|||
return MovieSessionSerializer | |||
|
|||
def get_queryset(self): | |||
query_set = ( |
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 already defined queryset with annotations above - just access it through self.
return query_set | ||
|
||
|
||
class OrderPagination(PageNumberPagination): |
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.
would be better structure to put pagination in a spearate file
pagination_class = OrderPagination | ||
|
||
def get_queryset(self): | ||
return self.queryset.filter(user=self.request.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.
N+1 problem not solved 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.
ok
|
||
from cinema.models import Genre, Actor, CinemaHall, Movie, MovieSession | ||
from cinema.models import Genre, Actor, CinemaHall, Movie, MovieSession, 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.
If importing more than two items, it is better to write them on separate lines. This improves readability and maintenance of the code.
Example:
From taxi.models import (
Driver,
Manufacturer,
Car
)
Read more about topic here
@@ -6,7 +6,7 @@ | |||
ActorViewSet, | |||
CinemaHallViewSet, | |||
MovieViewSet, | |||
MovieSessionViewSet, | |||
MovieSessionViewSet, OrderViewSet, |
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.
Inconsistent. Just move to a new line.
@@ -15,6 +15,7 @@ | |||
router.register("cinema_halls", CinemaHallViewSet) | |||
router.register("movies", MovieViewSet) | |||
router.register("movie_sessions", MovieSessionViewSet) | |||
router.register("orders", OrderViewSet) | |||
|
|||
urlpatterns = [path("", include(router.urls))] |
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 could simplify it to urlpatterns = router.urls
if u see only one commit just reject it