Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Solution #671

wants to merge 2 commits into from

Conversation

Bogdan-Rylov
Copy link

No description provided.

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")

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
Comment on lines 140 to 141
if self.action == "retrieve":
return OrderSerializer

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()

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
Copy link

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



class TicketDetailSerializer(TicketSerializer):
movie_session = MovieSessionSerializer(many=False, read_only=False)
Copy link

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)
Copy link

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
Copy link

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
Copy link

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
Copy link

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)
Copy link

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):

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

Copy link

@Oleksl888 Oleksl888 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants