diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 5a78f7b2..84b201bf 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -87,7 +87,7 @@ from cookbook.serializer import (AutomationSerializer, BookmarkletImportListSeri SupermarketCategorySerializer, SupermarketSerializer, SyncLogSerializer, SyncSerializer, UnitSerializer, UserFileSerializer, UserSerializer, UserPreferenceSerializer, - UserSpaceSerializer, ViewLogSerializer, AccessTokenSerializer) + UserSpaceSerializer, ViewLogSerializer, AccessTokenSerializer, FoodSimpleSerializer) from cookbook.views.import_export import get_integration from recipes import settings @@ -533,6 +533,11 @@ class FoodViewSet(viewsets.ModelViewSet, TreeMixin): .prefetch_related('onhand_users', 'inherit_fields', 'child_inherit_fields', 'substitute') \ .select_related('recipe', 'supermarket_category') + def get_serializer_class(self): + if self.request and self.request.query_params.get('simple', False): + return FoodSimpleSerializer + return self.serializer_class + @decorators.action(detail=True, methods=['PUT'], serializer_class=FoodShoppingUpdateSerializer, ) # TODO DRF only allows one action in a decorator action without overriding get_operation_id_base() this should be PUT and DELETE probably def shopping(self, request, pk): @@ -655,7 +660,7 @@ class IngredientViewSet(viewsets.ModelViewSet): def get_serializer_class(self): if self.request and self.request.query_params.get('simple', False): return IngredientSimpleSerializer - return IngredientSerializer + return self.serializer_class def get_queryset(self): queryset = self.queryset.filter(step__recipe__space=self.request.space) diff --git a/vue/src/components/GenericMultiselect.vue b/vue/src/components/GenericMultiselect.vue index 5c09566b..a5a2fbb4 100644 --- a/vue/src/components/GenericMultiselect.vue +++ b/vue/src/components/GenericMultiselect.vue @@ -155,8 +155,9 @@ export default { pageSize: this.limit, query: query, limit: this.limit, + options: {query: {simple: 1}}, // for API endpoints that support a simple view } - console.log(query, options) + this.genericAPI(this.model, this.Actions.LIST, options).then((result) => { this.objects = this.sticky_options.concat(result.data?.results ?? result.data) if (this.nothingSelected && this.objects.length > 0) { diff --git a/vue/src/utils/utils.js b/vue/src/utils/utils.js index 8eb4e918..fda87dbb 100644 --- a/vue/src/utils/utils.js +++ b/vue/src/utils/utils.js @@ -359,6 +359,7 @@ export const ApiMixin = { } }, methods: { + // if passing parameters that are not part of the offical schema of the endpoint use parameter: options: {query: {simple: 1}} genericAPI: function (model, action, options) { let setup = getConfig(model, action) if (setup?.config?.function) {