mirror of
https://github.com/wger-project/wger.git
synced 2026-02-18 00:17:51 +01:00
Use submission manager for ingredients
This change also filters the API results
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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
|
||||
"""
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user