-
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 #671
base: master
Are you sure you want to change the base?
Solution #671
Conversation
class MovieSessionDetailSerializer(MovieSessionSerializer): | ||
movie = MovieListSerializer(many=False, read_only=True) | ||
cinema_hall = CinemaHallSerializer(many=False, read_only=True) | ||
taken_places = TicketListSerializer(many=True, source="tickets") |
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.
I think here you can add read_only = True
cinema/views.py
Outdated
if self.action == "retrieve": | ||
return OrderSerializer |
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 delete this if
|
||
|
||
class OrderViewSet(viewsets.ModelViewSet): | ||
queryset = Order.objects.all() |
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 may sense to use prefetch_related here
cinema/views.py
Outdated
return OrderListSerializer | ||
|
||
if self.action == "retrieve": | ||
return OrderSerializer |
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.
return self.serializer_class because otherwise it's pointless to set serializer_class attribute in this case
cinema/serializers.py
Outdated
|
||
|
||
class TicketDetailSerializer(TicketSerializer): | ||
movie_session = MovieSessionSerializer(many=False, read_only=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.
False is a default value for both params
class TicketDetailSerializer(TicketSerializer): | ||
movie_session = MovieSessionSerializer(many=False, read_only=False) | ||
|
||
|
||
class MovieSessionDetailSerializer(MovieSessionSerializer): | ||
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.
False is a default value for this param
cinema/views.py
Outdated
@@ -34,6 +38,25 @@ 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
cinema/views.py
Outdated
@@ -48,11 +71,73 @@ 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.
call super method instead
cinema/views.py
Outdated
def get_serializer_class(self): | ||
if self.action == "list": | ||
return MovieSessionListSerializer | ||
|
||
if self.action == "create": | ||
return MovieSessionListPOSTSerializer | ||
|
||
if self.action == "retrieve": | ||
return MovieSessionDetailSerializer | ||
|
||
return MovieSessionSerializer |
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.
return self.serializer_class?
cinema/views.py
Outdated
pagination_class = OrderSetPagination | ||
|
||
def get_queryset(self): | ||
queryset = 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.
call super method instead
return self.serializer_class | ||
|
||
|
||
class OrderSetPagination(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.
better to put this in separate file to better structure code
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.
Well done!
No description provided.