# coding=utf-8

from rest_framework import serializers
from .models import UsedVehicle


class UsedVehicleSerializer(serializers.ModelSerializer):
    status_text = serializers.CharField(source='get_status_display', read_only=True)
    brand_name = serializers.CharField(source='brand.name', read_only=True)
    plate_date = serializers.DateField(format='%Y-%m-%d')
    factory_date = serializers.DateField(format='%Y-%m-%d ')

    class Meta:
        model = UsedVehicle
        fields = '__all__'

    def create(self, validated_data):
        instance = super(UsedVehicleSerializer, self).create(validated_data)
        return instance

    def update(self, instance, validated_data):
        instance = super(UsedVehicleSerializer, self).update(instance, validated_data)
        return instance
