from django.utils import timezone

from rest_framework import serializers

from .models import Product, ProductImage


class ProductImageSerializer(serializers.ModelSerializer):
    """ Serializer to retrieve images """

    class Meta:
        model = ProductImage
        fields = ("url", "order")
        read_only_fields = ("url", "order")


class ProductSerializer(serializers.ModelSerializer):
    """ Serializer to retrieve products """

    images = ProductImageSerializer(many=True)

    class Meta:
        model = Product
        fields = ["id", "name", "description", "images", "date_created"]
        read_only_fields = ["name", "description", "images", "date_created"]

from django.utils import timezone

from rest_framework import serializers

from .models import Product, ProductImage


class ProductImageSerializer(serializers.ModelSerializer):
    """ Serializer to retrieve images """

    class Meta:
        model = ProductImage
        fields = ("url", "order")
        read_only_fields = ("url", "order")


class ProductSerializer(serializers.ModelSerializer):
    """ Serializer to retrieve products """

    images = ProductImageSerializer(many=True)

    class Meta:
        model = Product
        fields = ["id", "name", "description", "images", "date_created"]
        read_only_fields = ["name", "description", "images", "date_created"]

Serializer to retrieve images Serializer to retrieve products