from rest_framework import serializers
from .models import Product, Order, OrderDetail


class ProductSerializer(serializers.ModelSerializer):

    class Meta:
        model = Product
        fields = ('__all__')


class OrderDetailSerializer(serializers.ModelSerializer):
    quantity = serializers.SerializerMethodField()

    basket = ProductSerializer(
        source='product',
        many=True,
        read_only=True
    )

    class Meta:
        model = OrderDetail
        fields = [
            'pk',
            'basket',
            'quantity'
        ]

    def get_quantity(self, obj):
        return len(obj.product.all())


class OrderSerializer(serializers.ModelSerializer):
    total_sum = serializers.SerializerMethodField()

    order_detail = OrderDetailSerializer(
        source='orderdetail_set',
        many=True,
        read_only=True
    )

    class Meta:
        model = Order
        fields = [
            'pk',
            'order_detail',
            'total_sum',
            'date_time'
        ]

    def get_total_sum(self, obj):
        return obj.get_total()

aebac8462f13c0c3a99e2bd8e032601cffee0759
<mask token>


class OrderDetailSerializer(serializers.ModelSerializer):
    <mask token>
    <mask token>


    class Meta:
        model = OrderDetail
        fields = ['pk', 'basket', 'quantity']

    def get_quantity(self, obj):
        return len(obj.product.all())


class OrderSerializer(serializers.ModelSerializer):
    total_sum = serializers.SerializerMethodField()
    order_detail = OrderDetailSerializer(source='orderdetail_set', many=
        True, read_only=True)


    class Meta:
        model = Order
        fields = ['pk', 'order_detail', 'total_sum', 'date_time']

    def get_total_sum(self, obj):
        return obj.get_total()

<mask token>


class OrderDetailSerializer(serializers.ModelSerializer):
    quantity = serializers.SerializerMethodField()
    basket = ProductSerializer(source='product', many=True, read_only=True)


    class Meta:
        model = OrderDetail
        fields = ['pk', 'basket', 'quantity']

    def get_quantity(self, obj):
        return len(obj.product.all())


class OrderSerializer(serializers.ModelSerializer):
    total_sum = serializers.SerializerMethodField()
    order_detail = OrderDetailSerializer(source='orderdetail_set', many=
        True, read_only=True)


    class Meta:
        model = Order
        fields = ['pk', 'order_detail', 'total_sum', 'date_time']

    def get_total_sum(self, obj):
        return obj.get_total()

<mask token>


class ProductSerializer(serializers.ModelSerializer):


    class Meta:
        model = Product
        fields = '__all__'


class OrderDetailSerializer(serializers.ModelSerializer):
    quantity = serializers.SerializerMethodField()
    basket = ProductSerializer(source='product', many=True, read_only=True)


    class Meta:
        model = OrderDetail
        fields = ['pk', 'basket', 'quantity']

    def get_quantity(self, obj):
        return len(obj.product.all())


class OrderSerializer(serializers.ModelSerializer):
    total_sum = serializers.SerializerMethodField()
    order_detail = OrderDetailSerializer(source='orderdetail_set', many=
        True, read_only=True)


    class Meta:
        model = Order
        fields = ['pk', 'order_detail', 'total_sum', 'date_time']

    def get_total_sum(self, obj):
        return obj.get_total()

from rest_framework import serializers
from .models import Product, Order, OrderDetail


class ProductSerializer(serializers.ModelSerializer):


    class Meta:
        model = Product
        fields = '__all__'


class OrderDetailSerializer(serializers.ModelSerializer):
    quantity = serializers.SerializerMethodField()
    basket = ProductSerializer(source='product', many=True, read_only=True)


    class Meta:
        model = OrderDetail
        fields = ['pk', 'basket', 'quantity']

    def get_quantity(self, obj):
        return len(obj.product.all())


class OrderSerializer(serializers.ModelSerializer):
    total_sum = serializers.SerializerMethodField()
    order_detail = OrderDetailSerializer(source='orderdetail_set', many=
        True, read_only=True)


    class Meta:
        model = Order
        fields = ['pk', 'order_detail', 'total_sum', 'date_time']

    def get_total_sum(self, obj):
        return obj.get_total()

from rest_framework import serializers
from .models import Product, Order, OrderDetail


class ProductSerializer(serializers.ModelSerializer):

    class Meta:
        model = Product
        fields = ('__all__')


class OrderDetailSerializer(serializers.ModelSerializer):
    quantity = serializers.SerializerMethodField()

    basket = ProductSerializer(
        source='product',
        many=True,
        read_only=True
    )

    class Meta:
        model = OrderDetail
        fields = [
            'pk',
            'basket',
            'quantity'
        ]

    def get_quantity(self, obj):
        return len(obj.product.all())


class OrderSerializer(serializers.ModelSerializer):
    total_sum = serializers.SerializerMethodField()

    order_detail = OrderDetailSerializer(
        source='orderdetail_set',
        many=True,
        read_only=True
    )

    class Meta:
        model = Order
        fields = [
            'pk',
            'order_detail',
            'total_sum',
            'date_time'
        ]

    def get_total_sum(self, obj):
        return obj.get_total()
