Merge pull request #1980 from 8633brown/nplusone

prefetch food relations #1965
This commit is contained in:
vabene1111
2022-08-05 07:53:01 +02:00
committed by GitHub

View File

@ -528,9 +528,10 @@ class FoodViewSet(viewsets.ModelViewSet, TreeMixin):
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