# coding=utf-8

from django.conf import settings
from rest_framework import serializers
from apps.customer.models import Customer, CustomerVehicle
from utils.exceptions import CustomError


class CustomerSerializer(serializers.ModelSerializer):
    gender_text = serializers.CharField(source='get_gender_display', read_only=True)
    img_url = serializers.SerializerMethodField()
    create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M', read_only=True)

    def get_img_url(self, obj):
        if obj.face:
            return '%s%s' % (settings.MEDIA_URL, obj.face.picture)
        return ''

    class Meta:
        model = Customer
        fields = '__all__'


class CustomerVehicleSerializer(serializers.ModelSerializer):
    img_url = serializers.SerializerMethodField()

    def get_img_url(self, obj):
        if obj.img:
            return '%s%s' % (settings.MEDIA_URL, obj.img.picture)
        return ''

    class Meta:
        model = CustomerVehicle
        fields = '__all__'


