# Copyright (C) 2018-2025 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later from rest_framework import serializers from ..models import Allergen, Food, BasicFood, TransformedFood, QRCode, Dish, Supplement, Order, FoodTransaction class AllergenSerializer(serializers.ModelSerializer): """ REST API Serializer for Allergen. The djangorestframework plugin will analyse the model `Allergen` and parse all fields in the API. """ class Meta: model = Allergen fields = '__all__' class FoodSerializer(serializers.ModelSerializer): """ REST API Serializer for Food. The djangorestframework plugin will analyse the model `Food` and parse all fields in the API. """ # This fields is used for autocompleting food in ManageIngredientsView # TODO Find a better way to do it owner_name = serializers.CharField(source='owner.name', read_only=True) class Meta: model = Food fields = ['name', 'owner', 'allergens', 'expiry_date', 'end_of_life', 'is_ready', 'order', 'owner_name'] class BasicFoodSerializer(serializers.ModelSerializer): """ REST API Serializer for BasicFood. The djangorestframework plugin will analyse the model `BasicFood` and parse all fields in the API. """ class Meta: model = BasicFood fields = '__all__' class TransformedFoodSerializer(serializers.ModelSerializer): """ REST API Serializer for TransformedFood. The djangorestframework plugin will analyse the model `TransformedFood` and parse all fields in the API. """ class Meta: model = TransformedFood fields = '__all__' class QRCodeSerializer(serializers.ModelSerializer): """ REST API Serializer for QRCode. The djangorestframework plugin will analyse the model `QRCode` and parse all fields in the API. """ class Meta: model = QRCode fields = '__all__' class DishSerializer(serializers.ModelSerializer): """ REST API Serializer for Dish. The djangorestframework plugin will analyse the model `Dish` and parse all fields in the API. """ class Meta: model = Dish fields = '__all__' class SupplementSerializer(serializers.ModelSerializer): """ REST API Serializer for Supplement. The djangorestframework plugin will analyse the model `Supplement` and parse all fields in the API. """ class Meta: model = Supplement fields = '__all__' class OrderSerializer(serializers.ModelSerializer): """ REST API Serializer for Order. The djangorestframework plugin will analyse the model `Order` and parse all fields in the API. """ class Meta: model = Order fields = '__all__' class FoodTransactionSerializer(serializers.ModelSerializer): """ REST API Serializer for FoodTransaction. The djangorestframework plugin will analyse the model `FoodTransaction` and parse all fields in the API. """ class Meta: model = FoodTransaction fields = '__all__'