# coding: utf-8
from rest_framework import serializers
from data.models import Skill, SkillValue


class ListSerializer(serializers.ModelSerializer):
    skill_value_list = serializers.SerializerMethodField(read_only=True)

    class Meta:
        model = Skill
        fields = [
            'skill_id',
            'target_unit',
            'target_member',
            'target_type',
            'target_num',
            'target_param',
            'skill_value_id',
            'skill_value_list',
            'comment'
        ]

    @staticmethod
    def get_skill_value_list(obj):
        return SkillValue.get_value_list(obj.skill_value_id)


class Costar(object):
    def __init__(self, name, count):
        self.name = name
        self.count = count


class CostarSerializer(serializers.Serializer):
    name = serializers.CharField(max_length=255)
    count = serializers.IntegerField()

    def create(self, validated_data):
        return Costar(**validated_data)

    def update(self, instance, validated_data):
        instance.name = validated_data.get('name', instance.name)
        instance.count = validated_data.get('count', instance.count)
        return instance

[((7, 23, 7, 72), 'rest_framework.serializers.SerializerMethodField', 'serializers.SerializerMethodField', (), '', False, 'from rest_framework import serializers\n'), ((35, 11, 35, 48), 'rest_framework.serializers.CharField', 'serializers.CharField', (), '', False, 'from rest_framework import serializers\n'), ((36, 12, 36, 38), 'rest_framework.serializers.IntegerField', 'serializers.IntegerField', ({}, {}), '()', False, 'from rest_framework import serializers\n'), ((25, 15, 25, 60), 'data.models.SkillValue.get_value_list', 'SkillValue.get_value_list', ({(25, 41, 25, 59): 'obj.skill_value_id'}, {}), '(obj.skill_value_id)', False, 'from data.models import Skill, SkillValue\n')]