'''
Created on Apr 10, 2013

@author: egiraldo
'''
from django.forms import widgets
from rest_framework import serializers
from conceptos.models import Concepto

class ConceptoSerializer(serializers.Serializer):
    id_concepto = serializers.Field()  # Note: `Field` is an untyped read-only field.
    id_transaccion = serializers.Field()  # Note: `Field` is an untyped read-only field.
    nombre = serializers.CharField(widget=widgets.Textarea,max_length=200)
    descripcion = serializers.CharField(widget=widgets.Textarea,max_length=200)
    id_tipo_documento = serializers.CharField(widget=widgets.Textarea,max_length=200)
    cod_concepto_generico = serializers.CharField(widget=widgets.Textarea,max_length=200)
    desc_concepto_generico = serializers.CharField(widget=widgets.Textarea,max_length=200)
    prueba = serializers.Field() 
    def restore_object(self, attrs, instance=None):
        if instance:
            # Update existing instance
            instance.id_transaccion = attrs.get('id_transaccion', instance.id_transaccion)
            instance.nombre = attrs.get('nombre', instance.nombre)
            instance.id_tipo_documento = attrs.get('id_tipo_documento', instance.id_tipo_documento)
            instance.descripcion = attrs.get('descripcion', instance.descripcion)
            instance.id_concepto_generico = attrs.get('id_concepto_generico', instance.id_concepto_generico)
            instance.cod_concepto_generico = attrs.get('cod_concepto_generico', instance.cod_concepto_generico)
            instance.desc_concepto_generico = attrs.get('desc_concepto_generico', instance.desc_concepto_generico)
            return instance
        # Create new instance
        return Concepto(**attrs)