'''
Created on Apr 10, 2013

@author: egiraldo
'''
from django.forms import widgets
from rest_framework import serializers
from tabla_propiedades.models import Tabla_Propiedades
class TablaPropiedadesSerializer(serializers.Serializer):
    id_tabla_propiedades = serializers.Field()  # Note: `Field` is an untyped read-only field.
    nombre = serializers.CharField(widget=widgets.Textarea,max_length=200)
    valor = serializers.CharField(widget=widgets.Textarea,max_length=200)
    def restore_object(self, attrs, instance=None):
        if instance:
            # Update existing instance
            instance.id_tabla_propiedades = attrs.get('id_tabla_propiedades', instance.id_tabla_propiedades)
            instance.nombre = attrs.get('nombre', instance.nombre)
            instance.valor = attrs.get('valor', instance.valor)
            return instance
        # Create new instance
        return Tabla_Propiedades(**attrs)
