# coding=utf-8

from rest_framework import serializers
from .models import Option


class OptionSerializer(serializers.ModelSerializer):
    type_name = serializers.CharField(source='get_type_display', read_only=True)
    enable_text = serializers.SerializerMethodField()

    def get_enable_text(self, obj):
        if obj.enable:
            return u'是'
        return u'否'

    class Meta:
        model = Option
        fields = '__all__'

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

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