'''
Created on Apr 10, 2013

@author: egiraldo
'''
from django.forms import widgets
from rest_framework import serializers
from campo_valor.models import Campo_Valor
class CampoValorSerializer(serializers.Serializer):
    id_campo_valor = serializers.Field()  # Note: `Field` is an untyped read-only field.
    id_tabla = 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)
    def restore_object(self, attrs, instance=None):
        if instance:
            # Update existing instance
            instance.Tabla = attrs.get('Tabla', instance.Tabla)
            instance.nombre = attrs.get('nombre', instance.nombre)
            instance.descripcion = attrs.get('descripcion', instance.descripcion)
            return instance
        # Create new instance
        return Campo_Valor(**attrs)
