-
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
Resolve #669
base: master
Are you sure you want to change the base?
Resolve #669
Conversation
cinema/views.py
Outdated
queryset = ( | ||
MovieSession.objects.all() | ||
.select_related("movie", "cinema_hall") | ||
# .annotate( |
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.
Delete comments
if date: | ||
date = datetime.strptime(date, "%Y-%m-%d").date() | ||
queryset = queryset.filter(show_time__date=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.
In ma case such code works:
if date:
queryset = queryset.filter(show_time__date=date)
and you do not need one more raw
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 my case it unfortunately doesn't work
cinema/serializers.py
Outdated
tickets_available = serializers.SerializerMethodField() | ||
|
||
def get_tickets_available(self, obj): | ||
return obj.cinema_hall.capacity - obj.tickets.count() |
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 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): |
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 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) |
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.
By doing this you are overriding queryset with prefetch above
|
||
|
||
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.
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)
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.
Approved
@@ -1,6 +1,18 @@ | |||
from datetime import datetime | |||
from idlelib.query import Query |
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.
what is this import for?
No description provided.