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 #409

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

Solution #409

wants to merge 3 commits into from

Conversation

denys-source
Copy link

image

image

image

image

image

image

image

image

image

Comment on lines +64 to +67
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
context = super().get_context_data(**kwargs)
context["car_list"] = self.object.cars.select_related("manufacturer")
return context

Choose a reason for hiding this comment

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

For what purpose did you use this method instead of queryset optimization

Copy link
Author

Choose a reason for hiding this comment

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

I thought that Driver.objects.prefetch_related("cars__manufacturer") will cache related cars and corresponding manufacturers for every driver, but we need to cache related cars for only one driver. I tested these two approaches and the current one is faster:

.prefetch_related("cars__manufacturer"):
image

current one:
image

taxi/views.py Outdated Show resolved Hide resolved
taxi/views.py Outdated
@@ -94,15 +91,13 @@ class ManufacturerCreateView(LoginRequiredMixin, CreateView):
model = Manufacturer
fields = "__all__"
success_url = reverse_lazy("taxi:manufacturer-list")
template_name = "taxi/manufacturer_form.html"
context_object_name = "manufacturer"

Choose a reason for hiding this comment

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

context_object name is also redundant attribute

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