From 10fd2e5017b10d021217fecba35633b2ffbb17bc Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Mon, 5 Oct 2020 16:56:29 +0200 Subject: [PATCH] Use submission manager for ingredients This change also filters the API results --- wger/nutrition/api/views.py | 2 +- wger/nutrition/models.py | 4 ++++ wger/nutrition/views/ingredient.py | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/wger/nutrition/api/views.py b/wger/nutrition/api/views.py index 4210b343c..7a4a95d37 100644 --- a/wger/nutrition/api/views.py +++ b/wger/nutrition/api/views.py @@ -58,7 +58,7 @@ class IngredientViewSet(viewsets.ReadOnlyModelViewSet): """ API endpoint for ingredient objects """ - queryset = Ingredient.objects.all() + queryset = Ingredient.objects.accepted() serializer_class = IngredientSerializer ordering_fields = '__all__' filterset_fields = ('carbohydrates', diff --git a/wger/nutrition/models.py b/wger/nutrition/models.py index 9432358a3..918ce5b5b 100644 --- a/wger/nutrition/models.py +++ b/wger/nutrition/models.py @@ -46,6 +46,7 @@ from wger.core.models import Language from wger.utils.cache import cache_mapper from wger.utils.constants import TWOPLACES from wger.utils.fields import Html5TimeField +from wger.utils.managers import SubmissionManager from wger.utils.models import ( AbstractLicenseModel, AbstractSubmissionModel @@ -263,6 +264,9 @@ class Ingredient(AbstractSubmissionModel, AbstractLicenseModel, models.Model): """ An ingredient, with some approximate nutrition values """ + objects = SubmissionManager() + """Custom manager""" + ENERGY_APPROXIMATION = 15 """ diff --git a/wger/nutrition/views/ingredient.py b/wger/nutrition/views/ingredient.py index c4441bf4b..c1f266447 100644 --- a/wger/nutrition/views/ingredient.py +++ b/wger/nutrition/views/ingredient.py @@ -83,8 +83,8 @@ class IngredientListView(ListView): native language, see load_ingredient_languages) """ languages = load_ingredient_languages(self.request) - return (Ingredient.objects.filter(language__in=languages) - .filter(status=Ingredient.STATUS_ACCEPTED) + return (Ingredient.objects.accepted() + .filter(language__in=languages) .only('id', 'name')) def get_context_data(self, **kwargs):