# coding=utf-8


from rest_framework import serializers

from apps.customer.models import SuperiorDistributor

from apps.base import Formater


class DistributorSerializer(serializers.ModelSerializer):
    name = serializers.CharField(source='customer.name', read_only=True)
    total_count = serializers.CharField(source='customer.success_count', read_only=True)
    total_amount = serializers.SerializerMethodField()

    class Meta:
        model = SuperiorDistributor
        fields = ('name', 'total_count', 'total_amount', )

    def get_total_amount(self, obj):
        return Formater.formatValueShow(obj.customer.total_amount)
