From 70b2bd6ccf7935598ce6f9c3de625a64b33ceb49 Mon Sep 17 00:00:00 2001 From: 8633brown Date: Thu, 4 Aug 2022 22:11:48 +0100 Subject: [PATCH] prefetch food relations #1965 --- cookbook/views/api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 3d5252435f..3f2053d61b 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -527,9 +527,10 @@ def get_queryset(self): shopping_status = ShoppingListEntry.objects.filter(space=self.request.space, food=OuterRef('id'), checked=False).values('id') # onhand_status = self.queryset.annotate(onhand_status=Exists(onhand_users_set__in=[shared_users])) - return self.queryset.annotate(shopping_status=Exists(shopping_status)).prefetch_related('onhand_users', - 'inherit_fields').select_related( - 'recipe', 'supermarket_category') + return self.queryset\ + .annotate(shopping_status=Exists(shopping_status))\ + .prefetch_related('onhand_users', 'inherit_fields', 'child_inherit_fields', 'substitute')\ + .select_related('recipe', 'supermarket_category') @decorators.action(detail=True, methods=['PUT'], serializer_class=FoodShoppingUpdateSerializer, ) # TODO DRF only allows one action in a decorator action without overriding get_operation_id_base() this should be PUT and DELETE probably