Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Use submission manager for ingredients

Roland Geider10fd2e5017b1
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):