Skip to content

Commit

Permalink
11
Browse files Browse the repository at this point in the history
  • Loading branch information
fabilya committed Oct 1, 2023
1 parent 82696f6 commit 5c27eb5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 0 additions & 2 deletions backend/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class IngredientFilter(filters.FilterSet):
"""Filtering ingredients by name."""

name = filters.CharFilter(
field_name='name',
Expand All @@ -17,7 +16,6 @@ class Meta:


class RecipeFilter(filters.FilterSet):
"""Filter by author, favorites, shopping list and tags."""

tags = filters.AllValuesMultipleFilter(field_name='tags__slug')
is_favorited = filters.BooleanFilter(method='filter_is_favorited')
Expand Down
14 changes: 7 additions & 7 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ def download_shopping_cart(self, request):
if not user.shoppingcart.exists():
return Response(status=status.HTTP_400_BAD_REQUEST)

ingredients = (IngredientAmount.objects.filter(
recipe__shoppingcart__user=request.user
).values(
'ingredients__name',
'ingredients__measurement_unit'
).annotate(amount=Sum('recipe__amount')).order_by())
shopping_cart = (
request.user.shoppingcart.recipe.
values(
'ingredients__name',
'ingredients__measurement_unit'
).annotate(amount=Sum('recipe__amount')).order_by())

today = datetime.today()
shopping_list = (
Expand All @@ -144,7 +144,7 @@ def download_shopping_cart(self, request):
f'- {ingredient["ingredient__name"]} '
f'({ingredient["ingredient__measurement_unit"]})'
f' - {ingredient["cart_amount"]}'
for ingredient in ingredients
for ingredient in shopping_cart
])
shopping_list += f'\n\nFoodgram ({today:%Y})'

Expand Down

0 comments on commit 5c27eb5

Please sign in to comment.