from rest_framework import serializers from .models import Plant, PlantImage class PlantImageSerializer(serializers.ModelSerializer): class Meta: model = PlantImage fields = ['id', 'image'] # Fields to expose for each image class PlantSerializer(serializers.ModelSerializer): images = PlantImageSerializer(many=True, read_only=True) # Include related images class Meta: model = Plant fields = ['id', 'name', 'description', 'buy_price', 'sell_price', 'stock', 'images'] # Add the `images` field extra_kwargs = { 'buy_price': {'required': False, 'allow_null': True}, 'sell_price': {'required': False, 'allow_null': True}, 'description': {'required': False, 'allow_null': True}, }