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

Resolve #669

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

Resolve #669

wants to merge 4 commits into from

Conversation

ihorutkin
Copy link

No description provided.

cinema/views.py Outdated
queryset = (
MovieSession.objects.all()
.select_related("movie", "cinema_hall")
# .annotate(

Choose a reason for hiding this comment

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

Delete comments

Comment on lines +104 to +106
if date:
date = datetime.strptime(date, "%Y-%m-%d").date()
queryset = queryset.filter(show_time__date=date)

Choose a reason for hiding this comment

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

In ma case such code works:

      if date:
           queryset = queryset.filter(show_time__date=date)

and you do not need one more raw

Copy link
Author

Choose a reason for hiding this comment

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

In my case it unfortunately doesn't work

tickets_available = serializers.SerializerMethodField()

def get_tickets_available(self, obj):
return obj.cinema_hall.capacity - obj.tickets.count()

Choose a reason for hiding this comment

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

This is quiet inefficient because we will have to query database for tickets.count() on every entry in a list. Better to override queryset and use annotate()

cinema/views.py Outdated
@@ -56,3 +113,30 @@ def get_serializer_class(self):
return MovieSessionDetailSerializer

return MovieSessionSerializer


class OrderPagination(PageNumberPagination):

Choose a reason for hiding this comment

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

better to put pagination in separate file to structure code better

cinema/views.py Outdated
pagination_class = OrderPagination

def get_queryset(self):
return Order.objects.filter(user=self.request.user)

Choose a reason for hiding this comment

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

By doing this you are overriding queryset with prefetch above



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.

you can remove this since you always override queryset in method below, OR
you can remove get_queryset() method and assign it here:
queryset = Order.objects.prefetch_related(
"tickets__movie_session__movie",
"tickets__movie_session__cinema_hall"
).filter(user=self.request.user)

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.

Approved

@@ -1,6 +1,18 @@
from datetime import datetime
from idlelib.query import Query

Choose a reason for hiding this comment

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

what is this import for?

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.

3 participants