diff --git a/cookbook/models.py b/cookbook/models.py index 6c7761b2d..5a9310242 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -722,25 +722,6 @@ class Ingredient(ExportModelOperationsMixin('ingredient'), models.Model, Permiss space = models.ForeignKey(Space, on_delete=models.CASCADE) objects = ScopedManager(space='space') - def __str__(self): - food = "" - unit = "" - if self.always_use_plural_food and self.food.plural_name not in (None, "") and not self.no_amount: - food = self.food.plural_name - else: - if self.amount > 1 and self.food.plural_name not in (None, "") and not self.no_amount: - food = self.food.plural_name - else: - food = str(self.food) - if self.always_use_plural_unit and self.unit.plural_name not in (None, "") and not self.no_amount: - unit = self.unit.plural_name - else: - if self.amount > 1 and self.unit is not None and self.unit.plural_name not in (None, "") and not self.no_amount: - unit = self.unit.plural_name - else: - unit = str(self.unit) - return str(self.amount) + ' ' + str(unit) + ' ' + str(food) - class Meta: ordering = ['order', 'pk'] indexes = ( diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 695dd2ee1..2b54d50ff 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -1051,6 +1051,21 @@ class ShoppingListEntryViewSet(viewsets.ModelViewSet): Q(created_by=self.request.user) | Q(shoppinglist__shared=self.request.user) | Q(created_by__in=list(self.request.user.get_shopping_share())) + ).prefetch_related( + 'created_by', + 'food', + 'food__properties', + 'food__properties__property_type', + 'food__inherit_fields', + 'food__supermarket_category', + 'food__onhand_users', + 'food__substitute', + 'food__child_inherit_fields', + + 'unit', + 'list_recipe', + 'list_recipe__mealplan', + 'list_recipe__mealplan__recipe', ).distinct().all() if pk := self.request.query_params.getlist('id', []):